ngx.socket.tcp不能在日志阶段使用。 https://github.com/openresty/lua-nginx-module#ngxsockettcp
但是我进行了测试,发现基于ngx.socket.tcp的lua-resty-mysql可以在日志阶段使用,为什么?
答案 0 :(得分:1)
您的测试错误。
这里很小test setup
如何运行:
docker-compose up
找出nginx端口:
docker ps
测试:
curl 127.0.0.1:<port>
这是证明:
nginx_1 | 2018/07/02 09:03:05 [error] 7#7: *1 failed to run log_by_lua*: /usr/local/openresty/lualib/resty/mysql.lua:520: API disabled in the context of log_by_lua*
nginx_1 | stack traceback:
nginx_1 | [C]: in function 'tcp'
nginx_1 | /usr/local/openresty/lualib/resty/mysql.lua:520: in function 'new'
nginx_1 | log_by_lua(nginx.conf:61):3: in function <log_by_lua(nginx.conf:61):1> while logging request, client: 192.168.112.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:33195"