Nginx Performance tuning

Home » Computer Articles » Linux » Nginx Performance tuning
January 13, 2014 Linux No Comments

Here I have collected the information to tuning your Nginx Web Server for better performance. Now of course you can tune your operating system, or purchase better hardware.

 

So you need to tune Nginx for your server. Example: how many CPU cores do you have on your server. So you need to setup Nginx to use them.

 

Of course if you find a good tuning option, feel free to leave a comment.

 

Will will start by editing the nginx.conf file. On Centos it is /etc/nginx/nginx.conf

Worker_processes = how many CPU cores you have on your web server.

 # cat /proc/cpuinfo| grep processor|wc -l (Put this number as your worker_processes) 

worker_processes 2; (This is on my VPS server)

 

Worker_connections  = is for the maximum clients the server can handle.

max_clients = worker_processes * worker_connections

Default is 768, but most documentation I have read seems to put it at 1024 (Thats 1024 connections per second on 1 core CPU). I read on the internet, if you want to hit 100k connections a minute, you would set this at 19000 on a 2 CPU core, 2G of ram server.

worker_connections 1024;

 

Worker_rlimit_nofile  is for how many files can be opened. So far the best information I have found here is to use 2 for each connection and 3 if using with a proxy. Make sure and check how many open files you have on the server  # sysctl fs.file-max, make sure you have enough. On my server I had 98911. You can't exceed this amount.

worker_rlimit_nofile 2048;

 

Sendfile

sendfile        on;

Keepalive_timeout

keepalive_timeout  2;

 

Reset_timedout_connection

reset_timedout_connection on;

 

Client_body_timout

client_body_timeout 10;

Send_timeout

send_timeout 2;

 

Gzip on the server to help with how much data is transfered.

gzip on;

gzip_disable "msie6";

gzip_comp_level 6;

gzip_min_length  1100;

gzip_buffers 16 8k;

gzip_proxied any;

gzip_types       text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;

References:

http://www.nginxtips.com/nginx-optimization-the-definitive-guide/

http://dak1n1.com/blog/12-nginx-performance-tuning

http://stackoverflow.com/questions/7325211/tuning-nginx-worker-process-to-obtain-100k-hits-per-min

http://www.gnupit.net/book/workerrlimitnofile 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.