Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Increate max no of open files limit in Ubuntu 16.04/18.04 for Nginx
# maximum capability of system
user@ubuntu:~$ cat /proc/sys/fs/file-max
# available limit
user@ubuntu:~$ ulimit -n
# To increase the available limit to say 200000
user@ubuntu:~$ sudo vim /etc/sysctl.conf
# add the following line to it
fs.file-max = 200000
# run this to refresh with new config
user@ubuntu:~$ sudo sysctl -p
# edit the following file
user@ubuntu:~$ sudo vim /etc/security/limits.conf
# add following lines to it
* soft nofile 200000
* hard nofile 200000
www-data soft nofile 200000
www-data hard nofile 200000
root soft nofile 200000
root hard nofile 200000
# edit the following file
user@ubuntu:~$ sudo vim /etc/pam.d/common-session
# add this line to it
session required
# logout and login and try the following command
user@ubuntu:~$ ulimit -n
# now you can increase no.of.connections per Nginx worker
# in Nginx main config /etc/nginx/nginx.conf
worker_connections 200000;
worker_rlimit_nofile 200000;
Copy link

loburets commented Jun 20, 2018

Cook, thank you

Copy link

NiloofarGheibi commented Jul 8, 2018


Copy link

sleshJdev commented Jul 19, 2018

Doesn't work for Ubuntu 18.04

Copy link

muhmushtaha commented Jul 21, 2018

same to me, did you change it?

Copy link

RomaZveR25 commented Jul 29, 2018

One more point, if you use systemd, then need edit


Copy link

WanLinLin commented Oct 30, 2018

Shouldn't L16 add the /etc/sysctl.conf file?

user@ubuntu:~$ sudo sysctl -p

Copy link

luckydev commented Nov 11, 2018

Doesn't work for Ubuntu 18.04

I just updated the gist by adding nginx config worker_rlimit_nofile and followed all of the steps in Ubuntu 18.04. I could see the limit increase during the last ulimit -n step.

Copy link

vasinkd commented Nov 20, 2018

Doesn't work for Ubuntu 18.04

It seems that on Ubuntu 18.04 one should set a separate limit for graphical login.
Checkout this topic for more info.

Copy link

krishan-kumar-mourya commented May 28, 2020

Cool, Thanks!

Copy link

wyyl1 commented Jun 10, 2020

Copy link

tencentemr commented Oct 24, 2021

Must restart! Change the maximum number of open files in ubuntu 18.10

not necessary. at least in 18.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment