How to install nginx web server on CentOS or Debian

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Configuring Nginx

Configuring nginx is not really the hardest, but you do need to know some little tricks. If have used a bit apache web server in MPM worker mode, this is a bit similar in thinking. Nginx is good because it can scale using a specific number of workers (usually the number CPU = number of workers), and these workers can have different pool size. The main configuration of Nginx web server is in:

Open this with favorite editor, nano or vi or whatever, and there you will see:

We specify that we want nginx to run as user “nginx”, for security reasons is good to leave it like it is. The next one is the important one, you need to change this to the number of cores you have, for example, a dual-core would use a value of 2 workers while a single core would use 1. Of course you can use a higher number, but it won’t scale well. I’m leaving it as it is on my little test since I only gave one CPU core to my virtual test machine.

The worker_connections and worker_processes from the main configuration file allows you to calculate the max clients your server can handle:

In a reverse proxy situation, max clients becomes

Since a browser opens 2 connections by default to a server and nginx uses the fds (file descriptors) from the same pool to connect to the upstream backend.

Next I recommend you remove the comment from the gzip if its there, and turn gzip compression on.

And that is all for your main configuration file, next you need to create your virtualhost configuration in the location included in the main configuration file:

Well for both distribution you can use just the /conf.d/ folder, but its recommended you use them as they have been structured so that you can keep track of your settings, so for Debian, add your virtualhost configuration in the folder /etc/nginx/sites-enabled/.

A default vhost configuration is as follows:

The above default configuration is linked to domain.com and has document root set to /var/www/ and aswell as reading default index.html or index.htm. I highlighted what you need to be careful of and what you should change if you wish to use this configuration.

That’s it for now, if you have questions, please let me know by commenting below.

Pages: 1 2

Request an article ←