Few nginx.conf configuration options for Nginx to
improve webserver performance
From my previous two articles
How to install nginx webserver from source on Debian Linux /
Install Latest Nginx on Debian ,
How to enable output compression (gzipfile content compression) in
nginx webserver , I have explained how the Nginx server can be
installed and configured easily.
As I'm continuing my nginx adventures this days, by trying to take
the best out of the installed nginx server, I've found
few
configuration options, which does improve nginx's server
performance and thought it might be nice to share it here in
hope that some other nginx novice might benefit out if them.
To setup and start using the options you will have of course to
place the conf directives in
/usr/local/nginx/conf/nginx.conf or wherever your nginx.conf
is located.
The configuration options should be placed in nginx's conf section
which starts up with:
http {
Here are the configuration options useful in hastening my nginx's
performance:
1. General options nginx settings
## General Options
ignore_invalid_headers on;
keepalive_requests 2000;
recursive_error_pages on;
server_name_in_redirect off;
server_tokens off;
2. Connection timeout nginx settings
## Timeouts
client_body_timeout 60;
client_header_timeout 60;
keepalive_timeout 60 60;
send_timeout 60;
expires 24h;
3. server options for better nginx tcp/ip performance
## TCP options
tcp_nodelay on;
tcp_nopush on;
4. Increase the number of nginx worker processes
Somewhere near the beginning of nginx.conf file you should have the
directive option:
worker_processes 1;
Make sure you change this option to:
worker_processes 4;
This will increase the number of spawned nginx worker processes in
a way that more spawned threaded servers will await for client
connections:
Being done with all the above settings, as a next step you have to
restart the nginx server, in my case via the init script:
debian:~# /etc/init.d/nginx restart
Restarting nginx: nginx.
Now to check everything is fine with nginx and more specific that
the
worker_processes 4 options has taken place issue the
command:
debian:~# ps axu |grep -i nginx|grep -v grep
root 20456 0.0 0.0 25280 816 ? Ss 10:35 0:00 nginx: master process
/usr/local/nginx/sbin/nginx
nobody 20457 0.0 0.0 25844 1820 ? S 10:35 0:00 nginx: worker
process
nobody 20458 0.0 0.0 25624 1376 ? S 10:35 0:00 nginx: worker
process
nobody 20459 0.0 0.0 25624 1376 ? S 10:35 0:00 nginx: worker
process
nobody 20460 0.0 0.0 25624 1368 ? S 10:35 0:00 nginx: worker
process
Above you notice the 4 nginx processes running with user nobody,
they're the same configured
worker_processes I just pointed
out above.