Reading Time: 2minutes
From my previous two articles How to install nginx webserver from source on Debian Linux / Install Latest Nginx on Debian and 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:
Here are the configuration options useful in hastening my nginx’s performance:
1. General options nginx settings
## General Options
2. Connection timeout nginx settings
keepalive_timeout 60 60;
3. server options for better nginx tcp/ip performance
## TCP options
4. Increase the number of nginx worker processes
Somewhere near the beginning of nginx.conf file you should have the directive option:
Make sure you change this option to:
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.