Nginx is one of the servers for web pages, both static and dynamic, that offer the best results, especially on web pages with a large number of visits. Although for users there are hardly any differences between using one server or another, for web administrators, one of the features beyond performance and the way of working with processes is configuration.
The first thing we have to do to use Nginx is to install it on our system. To do this, the first thing we must do is type in our terminal:
If we use a distribution based on Debian:
If we use a distribution based on Red Hat:
Once the installation of Nginx is finished, we will have the daemon running, ready to start loading our websites. We can easily control the web server daemon with the following commands:
One of the characteristics of this web server is that it allows you to configure the server and each one of the web pages that we mount on it separately. On the one hand, the basic configuration of the server is found in the file:
Within this file we will be able to configure the general functions of the web server, among others:
At the end of this file, inside the http block, we can see a default line called “include /etc/nginx/sites-enabled/*”. This line tells the server to load specific settings from different files and directories, in order to function as "virtual servers" and allow you to easily enable and disable settings without having to delete them.
As we have said, the configuration of the virtual server that creates us by default is found in the path “/etc/nginx/sites-available/default”.
If we edit this file we will be able to find, among other functions:
All the configuration of this file will be «overwritten» to the general configuration of the server.
By default, as indicated in the previous configuration file, when accessing the web through port 80, the index.html file will be opened by default. In the case of having a PHP server associated with Nginx (which we will see later), the file that will be opened by default will be index.php.
We can open the "index.html" file with "nano", see its content and even modify it or change it for another so that it shows our own web page.
With this, we will be able to set up a simple HTTP server ready to host static pages. In summary, some of the aspects that we must remember when configuring our server are: