Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saifat29/56ce067318f4e783cb60cc05ca7a96ec to your computer and use it in GitHub Desktop.
Save saifat29/56ce067318f4e783cb60cc05ca7a96ec to your computer and use it in GitHub Desktop.
Increase 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
708444
# available limit
user@ubuntu:~$ ulimit -n
1024
# 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 nproc 200000
* hard nproc 200000
* soft nofile 200000
* hard nofile 200000
root soft nproc 200000
root hard nproc 200000
root soft nofile 200000
root hard nofile 200000
# edit the following files
user@ubuntu:~$ sudo vim /etc/pam.d/common-session
user@ubuntu:~$ sudo vim /etc/pam.d/common-session-noninteractive
# add this line to both
session required pam_limits.so
# logout and login and try the following command
user@ubuntu:~$ ulimit -n
200000
# 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;
Extra Reference - https://underyx.me/2015/05/18/raising-the-maximum-number-of-file-descriptors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment