What is NGINX?
Nginx is a web server, proxy, reverse proxy, smtp server and load balancer. Let's break down these concepts right away. Magic ceases to be magic when you understand how the world works.
A web server is a program that accepts and processes requests from clients using the HTTP and HTTPS protocols and returns a response to them in the form of an HTML page. The proxy server receives and processes client requests, and then passes them on to other programs. Reverse proxy server - receives the result of the work of other servers and gives it to clients. The SMTP server is the mail service server. A load balancer is a program that distributes network requests between servers, following the balancing settings.
In this way of working, NGINX can handle up to 1024 simultaneous requests, so it is great for busy websites such as online stores, search engines, and cloud storage, and NGINX also uses a modular system, thanks to which it can expand its functions.
Modules are configured through NGINX configuration files, and we'll talk about them.
NGINX works with two levels of configuration files. The first level is global, it includes the etc/nginx/nginx.conf configuration file. The second level is local, it includes configuration files for specific sites, usually located in /etc/nginx/site-available or /etc/nginx/conf.d/
nginx.conf is the root configuration file for NGINX. It contains its global settings:
the user under whose name Nginx will be launched;
pid file location;
how many worker processes will be launched;
restrictions on the number of connections;
content compression conditions
and much more.
With Nginx.conf, NGINX starts parsing configuration files that consist of directives. Directives can be simple - single-line and can be blocked. If a block directive contains another nested block directive, then that block directive is called a context.
All configurations are described using directives, they are also used to connect modules.
For example, in the configuration, I made on this project
The Behavior of this configuration above is described here:
server
{
listen 443 ssl;
root /var/www/html;
index index.php;
server_name localhost;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_protocols TLSv1.2;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}