18

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

2 Answers 2

40

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

3
  • 1
    Thats it! That fixed it. Oh you are a saviour. It works now even when the ULimit is not manually set in /etc/default/nginx file. Awesome. Thank you @Xaviour
    – Neel
    Oct 30, 2014 at 22:30
  • 1
    well done Xavier. Oct 31, 2014 at 0:05
  • 2
    @Xavier this did removed the error msg, but can you explain why this works without changing ulimit as mentioned in the answer below? google searches tell to change ulimit in limits.conf or the systcl.conf, but none works for me. Nov 11, 2019 at 14:14
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.

3
  • I am using init and havent installed systemctl. Would that make a difference?
    – Neel
    Oct 30, 2014 at 21:35
  • When I changed to Nginx user, the ulimit -Hn is showing correctly there. I then checked init.d/nginx and it checks if ULIMIT is set in default folder (where it is set already) and then its supposed to set that value but it doesnt: Check if the ULIMIT is set in /etc/default/nginx
    – Neel
    Oct 30, 2014 at 21:39
  • After changing file-max and as soon i run sysctl -p ubuntu 18.04.2 hangs, throws too many files open and doesn't boot, had to remove the code in secure boot to make the OS boot again. Nov 11, 2019 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .