James Bachini

Optimising Nginx in Linux

I found one of the servers was throwing up a 500 error quite regularly. I checked the logs and in /var/log/nginx/error.log I found the following errors:

socket() failed (24: Too many open files) while connecting to upstream, client
socket() failed (23: Too many open files in system) while connecting to upstream, client

Solution was to increase the number of worker connections and edit a few files to allow more open files on the file system.

// edit /etc/nginx/nginx.conf
worker_connections 8024;

//add line to /etc/sysctl.conf
fs.file-max = 120000

//add two lines to /etc/security/limits.conf
*                soft    nofile          30000
*                hard    nofile          60000

//then run:
sysctl -p

//restart nginx for good measure
/etc/init.d/nginx restart


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.