openresty / openresty/lua-resty-redis

Redis failed to connect: connection refused

Open
#178 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
2k
Forks
447
Avg merge
2h 24m
Merged PRs (30d)
3

Description

I'm struggling with this issue more than a week, and still cannot pull it off.
I'm trying to provision our environment using Ansible, and I want to provision a staging server, with the same environment as production, I have setup the Redis server, and it's running listening on 6379 I have nginx up and running and it's serving requests, but when it's got to the part of lua to connect to redis, it throw on me connection refused error.
Here is nginx debug log: Link

Redis Listening on 6379

$ sudo lsof -i -P -n | grep LISTEN | grep 6379
redis-ser  1978         redis    4u  IPv6 138447828      0t0  TCP *:6379 (LISTEN)
redis-ser  1978         redis    5u  IPv4 138447829      0t0  TCP *:6379 (LISTEN)

Connecting to Redis through Python

Python 2.7.12 (default, Oct  8 2019, 14:14:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import redis
redis.Redis(host='127.0.0.1', port=6379, db='0')
r.set("Test", 'value')
True
r.get("Test")
'value'

Lua Code:

local red = redis:new()
red:set_timeout(500)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
     ngx.say("Redis failed to connect: ", err)
     return
end

Nginx conf:

server {
    listen 8080;
    server_name xxx.com;
    access_log /var/log/nginx/xxxx_access.log;
    error_log /var/log/nginx/xxxx_error.log debug;

    proxy_redirect     off;
    proxy_set_header Host   $host;
    proxy_set_header REMOTE_ADDR $http_cf_connecting_ip;
    proxy_set_header X-Real-IP  $http_cf_connecting_ip;
    proxy_set_header X-URI  $uri;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-Protocol $scheme;

    location / {
        rewrite_by_lua_file '/var/www/xxxx/nginx/add_header_web.lua';
        proxy_pass http://xxxxx/;
    }
}

Environment

Redis 3.2.0
Nginx: openresty/1.7.7.2
configure arguments: --prefix=/usr/local/openresty/nginx --with-debug --with-cc-opt='-I/opt/ngx_openresty-1.7.7.2/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1 -DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2 -O2' --add-module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.57 --add-module=../xss-nginx-module-0.04 --add-module=../ngx_coolkit-0.2rc2 --add-module=../set-misc-nginx-module-0.28 --add-module=../form-input-nginx-module-0.10 --add-module=../encrypted-session-nginx-module-0.03 --add-module=../srcache-nginx-module-0.28 --add-module=../ngx_lua-0.9.14 --add-module=../ngx_lua_upstream-0.02 --add-module=../headers-more-nginx-module-0.25 --add-module=../array-var-nginx-module-0.03 --add-module=../memc-nginx-module-0.15 --add-module=../redis2-nginx-module-0.11 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.13 --add-module=../rds-csv-nginx-module-0.05 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/opt/ngx_openresty-1.7.7.2/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/lib' --conf-path=/etc/nginx/nginx.conf --with-http_realip_module --with-http_stub_status_module --with-http_geoip_module --with-http_ssl_module --with-http_sub_module --add-module=/opt/nginxmodules/nginx-upload-progress-module --add-module=/opt/nginxmodules/nginx-push-stream-module

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 Lua connection call, the nginx configuration, and the linked debug log, then compare the Redis listener details with the runtime environment provisioned by Ansible. Done means identifying why the nginx Lua request receives “connection refused” and documenting a verified working configuration or reproducible failure.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.