Nginx learning road --- the composition of nginx configuration file

This blog simply records the components of the Nginxmain configuration file.

First, the main configuration file is in this directory:

/usr/local/nginx/conf/

Then you can see that there is nginx.confa file called :

Insert picture description here


This is today's protagonist, Nginxthe main configuration file. You can use the vi/vimcommand to go in and view, because there are many #s in the configuration file, the beginning of it represents the content of the comment, we remove all the paragraphs beginning with #, and the simplified content is as follows:

Insert picture description here

According to the above files, we can clearly divide the nginx.conf configuration file into three parts:

Part 1: Global Block


From the beginning of the configuration file to the contents of the events block, some configuration instructions that affect the overall operation of the nginx server will be set, mainly including the configuration of the user (group) running the Nginx server, the number of worker processes allowed to be generated, the process PID storage path, and the log Storage path and type, and the introduction of configuration files, etc.

For example, the configuration in the first line above:

worker_processes 1;

This is the key configuration of the Nginx server concurrent processing service. The larger the worker_processes value, the more concurrent processing can be supported, but it will be restricted by hardware, software and other equipment

Part 2: events block


For example, the above configuration:

events {
    
    
	worker_connections 1024;
}

The commands involved in the events block mainly affect the network connection between the Nginx server and the user. Commonly used settings include whether to enable serialization of network connections under multiple work processes, whether to allow multiple network connections to be received at the same time, and which event-driven model is selected for processing Connection request, the maximum number of connections that each word process can support at the same time, etc.

The above example indicates that the maximum number of connections supported by each work process is 1024.

This part of the configuration has a greater impact on the performance of Nginx, and should be configured flexibly in practice .

Part 3: http block


This is the most frequent part of Nginx server configuration. Most of the functions such as proxy, cache, and log definition and the configuration of third-party modules are here.

It should be noted that: http block can also include http global block, server block.

http global block

The directives for http global block configuration include file import, MIME-TYPE definition, log customization, connection timeout time, upper limit of single link requests, etc.

server block

This is closely related to the virtual host. From the user's point of view, the virtual host is exactly the same as an independent hardware host. This technology was created to save the cost of Internet server hardware.

Each http block can include multiple server blocks, and each server block is equivalent to a virtual host.

And each server block is also divided intoGlobal server block, And can contain multiple locaton block.

  1. Global server block: The
    most common configuration is the monitoring configuration of the virtual machine host and the name or IP configuration of the virtual host.

  2. location block:

A server block can configure multiple location blocks.

The main function of this block is based on the request string received by the Nginx server (for example, server_name/uri-string), to perform string analysis other than the virtual host name (or IP alias) (for example, the preceding /uri-string) Match to process specific requests. Functions such as address orientation, data caching, response control, and many third-party modules are also configured here.

Guess you like

Origin blog.csdn.net/Jokeronee/article/details/108365116