nginx server config for high availability

September 28, 2015 1.1k views
Server Optimization Nginx LEMP PHP Ubuntu

Using the following setup my server is able to handle lots of (virtual) concurrent users.

worker_processes 4;
worker_connections 8192;
worker_rlimit_nofile 40000;

Here's how I calculated these values on a 8 GB RAM / 4 CPUs droplet:

worker_processes= 1x for each CPU
worker_connections= 2048 x 4 CPUs
worker_rlimit_nofile = roughly 10.000 per core (my wild guess)

  1. How can I improve my setup/calculation above?
  2. Does anyone have working numbers for the largest droplet 64 GB / 20 CPU ?
1 Answer

Those settings look sane to me and seem to follow best practices. This blog post has been helpful to me in understanding these setting:

Workers are not multi-threaded so they do not spread the per-connection across CPU cores. Thus it makes sense for us to run multiple workers, usually 1 worker per CPU core. For most work loads anything above 2-4 workers is overkill as nginx will hit other bottlenecks before the CPU becomes an issue and usually you’ll just have idle processes.

For more information on optimizing Nginx, check out:

by Alex Kavon
Nginx is a fast and lightweight alternative to the sometimes overbearing Apache 2. However, Nginx just like any kind of server or software must be tuned to help attain optimal performance. Here's how to optimize Nginx configuration.
Have another answer? Share your knowledge.