Nginx – Can’t raise nginx max files opened limit

nginxUbuntuulimit

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

/etc/security/limits.conf:

*               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
4096
root@ubuntu_ngix:~# ulimit -Sn
1024

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.

Best Answer

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