I'm running Ubuntu Server. This is what I've done:


*               soft    nofile          10240
*               hard    nofile          10240

And added in /etc/pam.d/common-session:

session required pam_limits.so

And nginx conf itself /etc/nginx/nginx.conf

user www-data;
worker_processes 1; #I have only 1 core
pid /run/nginx.pid;

events {
    worker_connections 10240;
    # multi_accept on;

worker_rlimit_nofile 10240;

But trying to confirm changes:

root@ubuntu_ngix:~# ulimit -Hn
root@ubuntu_ngix:~# ulimit -Sn

I have restart nginx and also my server, but still nothing. What am I doing wrong here?

I'm running nginx as www-data user.

  • What version of ubuntu? – h0tw1r3 Sep 11 '15 at 15:21
  • Ubuntu 14.04.3 LTS – Badr Hari Sep 11 '15 at 18:05

The config /etc/security/limits.conf is specific to PAM. PAM, in general, is not used by software that manages services such as nginx.

So everything from init, to upstart, to systemd do not use the limits.conf at all.

nginx has a specific configuration setting for increasing the file descriptor limit worker_rlimit_nofile.

Outside of all configuration blocks (not in http or a server) add:

worker_rlimit_nofile 10240
  • This won't set it for the master process. It will only work for worker processes. – Hassan Baig Feb 4 '19 at 23:17

Check the permissions of /etc/security/limits.conf. It should be world readable (mode 0644).

I've spent many moons trying to figure out why limits won't take effect before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.