openresty / redis2-nginx-module

Nginx upstream module for the Redis 2.0 protocol
http://wiki.nginx.org/HttpRedis2Module
901 stars 142 forks source link

redis pass to unix sockets working? #69

Open osevan opened 2 years ago

osevan commented 2 years ago

It is possible to use unix socket in redis pass instead of localhost IP?

Like unix://path/redis.sock?

Thanks and best regards.

tzukav commented 1 year ago

yeah, it is working, I just tested it now.

mkdir /var/run/redis/ && chown -R redis:www-data /var/run/redis

then, in your /etc/redis/redis.conf, search for "unixsocketperm". modify "unixsocket" and "unixsocketperm" as following: unixsocket /var/run/redis/redis.sock unixsocketperm 777

then, service redis-server restart.

then, in your nginx configuration, just pass to: unix://var/run/redis/redis.sock

woutd commented 8 months ago

@tzukav are you sure this is working? This does not seem to work for me at all.

connect() to unix:/... failed (11: Resource temporarily unavailable) while connecting to upstream

I have no trouble connecting to the UNIX socket with redis-cli -s unix:/...

It would be a very nice feature to use UNIX sockets with redis2-nginx-module.

tzukav commented 8 months ago

@tzukav are you sure this is working? This does not seem to work for me at all.

connect() to unix:/... failed (11: Resource temporarily unavailable) while connecting to upstream

I have no trouble connecting to the UNIX socket with redis-cli -s unix:/...

It would be a very nice feature to use UNIX sockets with redis2-nginx-module.

can i confirm this is still working.

tzukav commented 8 months ago

@woutd is nginx using www-data as user?

tzukav commented 8 months ago

"Resource temporarily unavailable" can be a user, permissions error. if the socket file exists, i'm pretty sure there is a user or permission error.

tzukav commented 8 months ago

you can try by changing the nginx user to root temporarily, restart nginx and then see if it is working or not

woutd commented 8 months ago

Thanks for your answer @tzukav. Sorry, I got it to work from the first time but was also doing some stress tests which caused the "Resource temporarily unavailable" error.

tzukav commented 8 months ago

@woutd redis has max connection set by default to something like 10k as i remember. consider increasing ulimit too, the process may be auto killed if something like max open files is hit.

woutd commented 8 months ago

That is true, I already increased maxclients and max number of open files (ulimit). The "Resource temporarily unavailable" errors are temporary. Seems to be some "connection build up" limit I am hitting. After a great number of clients are connected everything seems to work. But this is probably related with Redis, not the NGINX module. (I was hitting the max number of ephemeral ports using IP, that is why I am looking at UNIX sockets.)

Edit: Increasing tcp-backlog in Redis config resolved my issue.

tzukav commented 8 months ago

@woutd yeah, i had same problem with backlog long time ago but in nginx, not redis. backlog is a always a problem in high traffic scenarios. forgot to tell you about it. also, depending on what you are using redis for, you may want to take a look over https://nginx.org/en/docs/njs/reference.html#dict as a replace for redis non persistent data.

woutd commented 8 months ago

@tzukav looks nice. Thanks for the info and your support.

I guess this ticket can be closed as UNIX socket support certainly works.