Ubuntu 16 – how to increase maximum file open limit ( ulimit -n )

If you are setting up nginx,chances are you will discover your worker_connections is at some low number, such as 1024.
You can’t increase this number unless you increase kernel limit as well.
First of all run cat /proc/sys/fs/file-max to discover your maximum limit.

abc@ubuntu:~$ cat /proc/sys/fs/file-max
1048576
abc@ubuntu:~$ ulimit -n
1024

As you can see there’s plenty of space for improvement. Lets say I want my new ‘ulimit -n’ to read 131072.

abc@ubuntu:~$ sudo nano /etc/sysctl.conf

add

fs.file-max = 131072

run

sudo sysctl -p

edit

sudo nano /etc/security/limits.conf

add

* soft     nproc          131072    
* hard     nproc          131072   
* soft     nofile         131072   
* hard     nofile         131072
root soft     nproc          131072    
root hard     nproc          131072   
root soft     nofile         131072   
root hard     nofile         131072
sudo nano /etc/pam.d/common-session

add

session required pam_limits.so

And that’s it. Log out and in and try ulimit -n

abc@ubuntu:~$ ulimit -n 131072

Now you can edit nginx as well

events {
    worker_connections 131072;
    use epoll;
    multi_accept on;
}

Write a Comment

Comment

  1. Thanks for your tips. This is the only blog that worked to increase ulimit for me. The other blogs out there failed to mention fs.file-max settings.

  2. Not sure why you are doing all those steps but the second

    “fs.file-max = 131072”

    already broke my amazon machine.
    “Server refused our key” came after a reboot and trying to reconnect with putty. I do have plenty of resources on that machine and actually no idea whats the connection to my key.

Webmentions

  • medicament kamagra pharmacie sens ordonnance 2018-12-19

    est kamagra au comptoir en australie

    kamagra prix canada

  • kamagra přepraveno přes noc bez lékařského předpisu 2018-12-19

    nejlepší kamagra ceny online

    kupte si obecný kamagra bez lékařského předpisu

  • order itraconazole generic side effect 2018-12-19

    No perscription itraconazole next day

    itraconazole 50 mg low cost

  • buy cheap fildena medication interactions 2018-12-19

    how to order fildena generic online canada

    fildena uk where buy onlune

  • buying gabapentin cheap alternatives 2018-12-19

    buying gabapentin generic does it works

    how to order gabapentin toronto canada

  • buy cheap flexeril cyclobenzaprine lowest price 2018-12-19

    cheap flexeril cyclobenzaprine usa generic

    online order flexeril cyclobenzaprine american express

  • buy dutasteride generic good 2018-12-19

    buy dutasteride in Sydney

    cheapest buy dutasteride cost australia

  • Canadian avodart 2018-12-19

    buying avodart purchase from canada

    get avodart price dubai

  • discount staxyn buy mastercard 2018-12-19

    get staxyn generic switzerland

    how to buy staxyn purchase uk

  • buying xifaxan generic cheap 2018-12-19

    ordering xifaxan generic compare

    cheap xifaxan saturday delivery cod

  • canada rifaximin 2018-12-19

    online order rifaximin australia pharmacy

    buy rifaximin generic from canada

  • buying enclomiphene generic uk 2018-12-19

    cheapest buy enclomiphene cost at costco

    online order enclomiphene generic compare

  • androxal no doctor 2018-12-19

    cheapest buy androxal canada online order

    buy androxal generic new zealand