socket() failed 24: Too many open files) while connecting to upstream, client: server

If your nginx proxy shows such error, it means too many open files on your server and you should increase such values.

worker_rlimit_nofile 16384;

or if you are not on OpenVZ VPS, you can:

vi /etc/security/limits.conf
* hard nofile 500000
* soft nofile 500000
root hard nofile 500000
root soft nofile 500000

if it not works:

vi /etc/pam.d/common-session
session required pam_limits.so

vi /etc/sysctl.conf
fs.file-max = 2097152
sysctl -p

then cat /proc/sys/fs/file-max

Check limits of a running process:
ps aux | grep nginx
cat /proc/nginx_proc_ID/limits

Check limits for nginx user:
su – nginx -c ‘ulimit -aHS’ -s ‘/bin/bash’

ulimit -Hn / ulimit -Sn # this will show hard and soft limits

One thought on “socket() failed 24: Too many open files) while connecting to upstream, client: server

Leave a Reply

Your email address will not be published. Required fields are marked *