This is the second day of my participation in the August More text Challenge. For details, see:August is more challenging

On the first day, we learned what Nginx is, and mastered the installation and uninstall of Nginx. Then, we need to configure Nginx, so that Nginx can provide us with the services we need and become our own shape!

Nginx (1)

Nginx configuration file

  • nginx.conf
  • conf.d/default.conf

Conf is used as the main configuration file of Nginx, and conf.d/default.conf is used as the default sub-configuration file. In actual use, the main configuration file will automatically import other sub-configuration files.

Contents of the main configuration file

The following is a top-down analysis of the meanings of configuration:

User nginx: indicates the current user of the Nginx service. The default is nginx

Worker_processes AUTO: Specifies the number of Nginx processes. The default value is Auto, indicating that the number of processes is the same as the number of CPU cores

Error_log /var/log/nginx/error.log notice: Specifies the directory for storing nginx error logs and the log output level

Pid /var/run/nginx.pid: sets the pid saving path when the Nginx service is started

HTTP {} : This module is used to set most functions such as service information, proxy, log, forwarding request and so on. It is the most frequently used part

Include /etc/nginx/mime.types: introduces file extensions and type mapping tables

Default_type Application/OCTET -stream: indicates the default file type

Log — format main ‘$remote_addr -… ‘: Sets the Nginx logging mode

Access_log/var/log/nginx/access log main: set the nginx access log location

Sendfile on: Whether to enable the efficient transfer mode. It is enabled by default

#tcp_nopush on: reduces the number of network segments. This configuration does not take effect

Keepalive_timeout 65: indicates the duration of the request to stay connected to the Nginx server. It also indicates the timeout period, in seconds

#gzip on: whether to enable compression, default comment

Include /etc/nginx/conf.d/*. Conf: indicates the contents of sub-configuration file pairs in the main configuration file, indicating that all configuration files in the conf.d folder are imported to the main configuration file for effect

Default subconfiguration file content

The meanings of related configurations from top to bottom are as follows:server{}: Server is used to configure host parameters. An HTTP block can contain multiple server blocks. In this case, it can be used to listen on multiple ports on the host

Listen 80: listens to port 80 on the host

Server_name localhost: configure the listening domain name, domain name and port form a complete address, when the path to receive requests, Nginx will process

Location / {} : location is used to configure the matching URI and forward or process the request

Root /usr/share/nginx/html: indicates the root directory of the Nginx server

Index index. HTML index. HTM: index. HTML displays the page when requesting Nginx. The page is stored in the root directory of Nginx

Error_page 404/404.html: Access page corresponding to the default 404

This is the configuration file information generated after the Nginx installation is complete. By understanding the meaning of each property, we can set the value of the property to achieve different functions.

Recently, I have been working overtime every day. Only after work can I have time to learn and summarize. Take your time and come on!