Setting up NGINX as Reverse Proxy for Camping.Info

by Oliver 24. June 2013 23:08

worker_processes 1; #

Thanks to for helping me find out how many processor cores our VPS is using.

Fixing the painful "24: Too many open files" error in NGINX

When this error appears in your /var/etc/nginx/error.log file, you really want to do something about it. It basically tells you that some of your users are not being served content but instead receiving HTTP 500 errors generated by NGINX. Not a good thing!

To investigate the open file descriptors on your linux (we're running NGINX on Ubuntu 12.04), I followed advice from this post: Linux: Find Out How Many File Descriptors Are Being Used. Then, to fix the low limits I found, 1024 and 4096 for the soft and hard limits, respectively, the post Set ulimit parameters on ubuntu provided a good walkthrough to changing those limits persistently, i.e. even after a reboot. But I somehow had the feeling that in case of NGINX there had to be a simpler solution. Turns out, there is.

Let me introduce you to: worker_rlimit_nofile

This thread in the NGINX forums contained the hint I needed: Re: Handling nginx's too many open files even I have the correct ulimit. I had actually posted to that thread before and received the helpful answer over a month ago, but I somehow hadn't got around to implementing it. Until today. So here's what you need to do:

  1. Set the worker_rlimit_nofile (in the main context) to something significant (I used 65536 = 2^16) instead of the default 1024 as soft and 4096 as the hard limit.
  2. Also set worker_connections to the same number to allow for a lot of parallel connections, both from clients and to upstream servers.

Your nginx.conf file should now contain these lines:

   1: user                   www-data;
   2: worker_processes       1;
   3: worker_rlimit_nofile   65536;
   4: pid                    /var/run/;
   6: events {
   7:     worker_connections 65536;    ## default: 1024
   8:     # multi_accept on;
   9: }

Reload NGINX after configuration change

In a shell, tell NGINX to reload the configuration. You don't need to restart the whole process to get a configuration change live. Just run:

/usr/sbin/nginx -s reload


service nginx reload

Now enjoy thousands and thousands of parallel connections to your proxy server :-)

Comments (1) -

Bybdy Ukraine
6/25/2013 5:25:44 PM #

"worker_connections 65536;"
It's not "just number". Do you noticed that you have increased memory consumtion?


Add comment

  Country flag

  • Comment
  • Preview

About Oliver code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.