This article briefly introduces the basic contents of Nginx configuration file.
1.Nginx’s default configuration file
The default main configuration of Nginx is located in the conf folder of the installation directory, nginx.conf and nginx.conf.default. [Note: If they have not been changed, the contents of the two files here are the same. The function of nginx.conf.default is to facilitate users to restore the default configuration] Other files in the conf folder are used to configure different modules of Nginx.
2.nginx.conf file brief description
Nginx’s main configuration file is divided into several blocks, global block, events block, server block, and location block.
2.1 Global block
The part between the beginning of the nginx.conf file and the events block is a global block, which affects the entire Nginx world, including users (groups), the number of worker processes allowed to be generated, the log storage directory, and the directory of the pid file. . As shown below:
2.2 events block
The events block has a clear structure and is marked with two curly brackets. The events block mainly involves the network connection between the Nginx server and the user.
<code><span>events</span><span>{ worker_connections <span>1024</span>; }</span></code>
The default configured events block only configures the maximum number of connections allowed per worker process.
2.3 http block
The http block contains global blocks (http global blocks) that act within the http scope, as well as server blocks and location blocks.
In the http block structure shown in the figure above, the part of the configuration block from the beginning to the server block is the http global block. You can see that in the http global block, you can include mime.types, log customization, whether to use sendfile to transfer files, connection timeout and whether to use the gzip module, etc.
2.3.1 server block
Through the settings of the server block, the Nginx server can be made to serve several websites.
As shown in the figure above, multiple such server blocks can be configured in the http block to serve multiple websites respectively.
2.3.2 Location block
Each server block can contain multiple location blocks. Match the requests received by the Nginx server and process special requests. Location specific items, data caching and permission control can all be configured in the location block.
Reference:
1. "Detailed Explanation of Nginx High-Performance Web Server" edited by Miao Ze, Beijing: Electronic Industry Press, 2013.10
The above is a brief introduction to the basic configuration of the Nginx server, including all aspects. I hope it will be helpful to friends who are interested in PHP tutorials.