Closed czf0613 closed 2 years ago
is there any error log?
No any, it just shows that failed to connect to "my.redis.aliyuncs.com". It's quite weird.
can you post your nginx.conf, so we can reproduce this problem
Sure, please view the nginx configuration file in: https://czf-net.xyz/res/nginx.conf The lua script is also included at: https://czf-net.xyz/res/access_control.lua Thanks for your great help!
I am facing this error while using Kong. Is there any additional information I would be able to provide?
@czf0613 you need to specify a resolver. eg resolver 4.4.4.4 ipv6=off;
It does not work at all... But I tried another case, I add a TCP proxy in openresty like this:
stream { server { listen 30003; proxy_pass r-8vbiib2him1kzqtbhf.redis.zhangbei.rds.aliyuncs.com:6379; } }
This piece of code works no matter whether you specify the resolver or not, which means the default DNS resolver in my server is correct. I think it may still has some bugs in the lua-resty-redis. Thanks for your regard.
@czf0613 you need to specify a resolver. eg resolver 4.4.4.4 ipv6=off;
I agree with @czf0613 that there is a DNS bug here. My resolver is declared properly in /etc/resolv.conf - I shouldn't need to specify it elsewhere.
modified the lua code, and got the following error 2021/12/26 18:46:24 [error] 986#986: *6 [lua] access_control.lua:14: redis connection failed!no resolver defined to resolve "r-8vbiib2him1kzqtbhf.redis.zhangbei.rds.aliyuncs.com", client: 127.0.0.1, server: pic-bed.xyz, request: "GET /service HTTP/1.1", host: "127.0.0.1"
local redis_pack = require "resty.redis"
local redis = redis_pack:new()
redis:set_timeouts(1000, 1000, 1000)
-- writing connection address in this way is OK
-- local ok, err = redis:connect("10.0.0.205", 6379)
-- but failed in this way, I was wondering if there is any problem in DNS?
local ok, err = redis:connect("r-8vbiib2him1kzqtbhf.redis.zhangbei.rds.aliyuncs.com", 6379)
if not ok then
ngx.log(ngx.ERR, "redis connection failed!", err)
ngx.exit(502)
return
end
It still shows that 'no resolver defined to resolve "r-8vbiib2him1kzqtbhf.redis.zhangbei.rds.aliyuncs.com", client: 58.63.62.105, server: , request: "GET /res HTTP/1.1"'
@czf0613 Did you find a solution? Why did you close this?
Quite weird, I asked my cloud service provider and they gave me a DNS server. I configured my docker DNS resolver, and, it works. I cannot understand why...... I believe that it must be some problems in DNS, maybe some bugs in nginx, not the lua-resty-redis.
Thanks for the insight, appreciated
Edit: I seem to have fixed my issue by upgrading Kong from 2.6.0 to 2.7.0.
I see the document says you can connect to redis using "red:connect("127.0.0.1", 6379)", but I found something wrong when I use the host name instead of IP address. For example, I bought the redis server from the cloud service, they provided me a connection address "my.redis.aliyuncs.com". But it has an error when I use "red:connect("my.redis.aliyuncs.com", 6379)". Is there something wrong with DNS? Or, I just made a mistake? I am pretty sure that I can connect successfully by using other redis desktop manager.
I am looking forward to your reply. Thanks sincerely!