nginx "accept4() failed (24: Too many open files)"

harmonypersechino5348

Well-Known Member
Dec 6, 2020
45
3
8
NA
cPanel Access Level
Website Owner
I am getting the following error with nginx

Code:
2022/01/26 03:54:03 [crit] 28222#28222: accept4() failed (24: Too many open files)
2022/01/26 03:54:03 [crit] 28222#28222: accept4() failed (24: Too many open files)
2022/01/26 03:54:04 [crit] 28222#28222: accept4() failed (24: Too many open files)
2022/01/26 03:54:04 [crit] 28222#28222: accept4() failed (24: Too many open files)
2022/01/26 03:54:05 [crit] 28222#28222: accept4() failed (24: Too many open files)

I have came across https://support.cpanel.net/hc/en-us...e-the-number-of-open-files-allowed-for-Nginx- and made the changes however this did not fix the issue.

[root@home ~]# grep 'open file' /proc/$(pgrep -u root -f 'nginx: master')/limits
Code:
Max open files            99999                99999                files
The file limit is still set low

[root@home ~]# ulimit -Hn
Code:
4096
[root@home ~]# ulimit -Sn
Code:
1024

I came across other websites saying that I need to add

/etc/security/limits.conf
Code:
nginx       soft    nofile   10000
nginx       hard    nofile  30000
As nginx.conf is currently being run as nobody then I presume I need to change that to


Code:
nobody       soft    nofile   10000
nobody       hard    nofile  30000
When trying to verify the changes I get the error

[root@home ~]# su - nobody -c 'ulimit -Hn'
Code:
This account is currently not available.
How can I verify this is all I need to do?
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,484
2,605
363
cPanel Access Level
Root Administrator
Hey there! The "nobody" account wasn't available for SSH access because that user typically doesn't login and perform work, so the shell is set to nologin. Here's the output of the /etc/passwd file from an example system showing this:

Code:
# grep nobody /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
Nginx does indeed run as nobody just like Apache. To check a user's limits without shell, you can assign them a temporary session with this command. here's what I see on my personal machine:

Code:
# su - nobody -c 'ulimit -Hn' -s '/bin/bash'
4096
Can you try that to see if the values are now set how you expect?
 

harmonypersechino5348

Well-Known Member
Dec 6, 2020
45
3
8
NA
cPanel Access Level
Website Owner
Thank you for the reply.

Yes it seems that the values set in /etc/security/limits.conf should resolve this now.

Code:
[root@home ~]# su - nobody -c 'ulimit -Hn' -s '/bin/bash'
30000