ledgetech / ledgetech/lua-resty-http

通过`resty.http` 调用 https 请求,一直报错

Open
#297 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
2.1k
Forks
630
PR merge metrics
No merged PRs in 30d

Description

前提

电脑:
image

其他安装版本(使用nginx源码编译的方式集成 lua, 而非 openresty):

nginx version: nginx/1.23.4
lua version: Lua 5.4.5  Copyright (C) 1994-2023 Lua.org, PUC-Rio
luajit version: LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/(使用的是openresty中的版本)
openssl verions: 3.1.0
pcre version: 1.x

nginx需要的模块(从openresty的 github 中下载):

lua-nginx-module(master分支)
ngx_devel_kit(master分支)
lua-resty-core(master分支, 需要 `make` 和 `make install` 到`/xxx/restry`目录)
lua-resty-lrucache(master分支, 需要 `make` 和  `make install` 到`/xxx/restry`目录)

lua-resty-http 模块:

1. 下载: https://github.com/ledgetech/lua-resty-http/tree/master, 
2, 通过 make 命令安装到 `xxx/restry` 目录下

配置 nginx,添加 resty 目录映射:

http {
   ...
  
  # 添加 lua_package_path
 lua_package_path '/xxx/restry/lib/lua/?.lua;;';
 lua_package_cpath '/xxx/restry/lib/lua/?.so;;';

  ...
 
}
开发

因为后台是使用的 https 的链接, 所以想通过nginx lua 直接调用,代码如下:

-- http.test.lua
local http = require('resty.http')
local client = http.new()
local res, err = client:request_uri(
  'https://xxx.com:9090/xxx',  -- 具体地址是 https 开头, 带 9090 端口
  {
     method = 'GET',
     keepalive_timeout = 30000
  }
)

nginx 配置:

location /test {
        default_type 'application/json'; #返回Json文本
        content_by_lua_file /xxx/http.test.lua; -- 对应上面 http.test.lua 文件地址
 }

现在报错信息如下:

2023/05/12 15:41:42 [debug] 25930#0: *35 [lua] index.lua:71: send(): [Nginx Lua Http]**url: https://xxx.com:9090/xxx**
2023/05/12 15:41:42 [debug] 25930#0: *35 [lua] index.lua:72: send(): [Nginx Lua Http]**method: GET**
2023/05/12 15:41:42 [debug] 25930#0: *35 [lua] index.lua:73: send(): [Nginx Lua Http]**keepalive_timeout: 300000**
2023/05/12 15:41:43 [error] 25930#0: *35 lua entry thread aborted: runtime error: ...s/smile/tools/nginx/restry/lib/lua/resty/core/socket.lua:209: **dlsym(RTLD_DEFAULT, ngx_http_lua_ffi_socket_tcp_sslhandshake): symbol not found**
stack traceback:
coroutine 0:
	[C]: in function '__index'
	...s/smile/tools/nginx/restry/lib/lua/resty/core/socket.lua:209: in function 'sslhandshake'
	.../smile/tools/nginx/restry/lib/lua/resty/http_connect.lua:247: in function 'connect'
	/Users/smile/tools/nginx/restry/lib/lua/resty/http.lua:934: in function 'request_uri'
	./http/index.lua:77: in function 'send'
	/Users/smile/tools/nginx/nginx-code/https.test.lua:20: in main chunk, client: 127.0.0.1, server: localhost, request: "GET /testHttps/ HTTP/1.1", host: "localhost:9999"

查看 socket.lua 找到错误地方:
image

查看 http_connect.lua 找到错误地方:
image

http 请求正常,就是 https 报错,帮忙看一下,谢谢~

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the HTTPS request in http.test.lua and trace request_uri in resty/http.lua through resty/http_connect.lua to resty/core/socket.lua, focusing on the missing ngx_http_lua_ffi_socket_tcp_sslhandshake symbol. Reproduce the request with the reported nginx, LuaJIT, OpenSSL, and lua-nginx-module setup; done means identifying the build/configuration compatibility issue and documenting a verified resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.