nginx uLimit 'worker_connections exceed open file resource limit: 1024'

I keep getting this error in nginx/error.log and its driving me nuts:

8096 worker_connections exceed open file resource limit: 1024

I've tried everything I can think of and cant figure out what is limiting nginx here. Can you tell what am I missing?

nginx.conf has this:

worker_processes 4;
events {
        worker_connections 8096;
        multi_accept on;
        use epoll;
}

I changed my system's Ulimit in security/limits.conf like this:

# This is added for Open File Limit Increase
*               hard    nofile          199680
*               soft    nofile          65535

root            hard    nofile          65536
root            soft    nofile          32768

# This is added for Nginx User
nginx           hard    nofile          199680
nginx           soft    nofile          65535

It was still showing the error. So I also tried editing /etc/default/nginx and added this line:

ULIMIT="-n 65535"

It is still showing the same error. Can't figure out what is limiting the nginx worker connection to only 1024. Can you point me out?

I've got Debian 7 + nginx


Solution 1:

Set worker_rlimit_nofile 65535; in nginx.conf within the main context.

Solution 2:

Become the user:

su - nginx

Check the limits:

ulimit -Hn
ulimit -Sn

Edit the number of files the file system will let you have open:

vi /etc/sysctl.conf
fs.file-max = 70000

load your changes:

sysctl -p

See if that helps.