Overall understanding of Nginx configuration
By default, Nginx server configuration files are stored in the installation directory Conf, and the main configuration file is named nginx.conf. Its content is as follows:
<code><span>#user nobody; #全局块</span> worker_processes <span>1</span>; <span>#error_log logs/<span>error</span>.log;</span><span>#error_log logs/<span>error</span>.log notice;</span><span>#error_log logs/<span>error</span>.log info;</span><span>#pid logs/nginx.pid;</span>events { <span>#events 块</span> worker_connections <span>1024</span>; } http { <span>#http块</span> include mime.types; <span>#http全局块</span> default_type application/octet-stream; <span>#log_format main '$remote_addr - $remote_user [$time_local] "$request" '</span><span># '$status $body_bytes_sent "$http_referer" '</span><span># '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log logs/access.log main;</span> sendfile on; <span>#tcp_nopush on;</span><span>#keepalive_timeout 0;</span> keepalive_timeout <span>65</span>; <span>#gzip on;</span> server { <span>#server块</span> listen <span>80</span>; <span>#server全局块</span> server_name localhost; <span>#charset koi8-r;</span><span>#access_log logs/host.access.log main;</span> location / { <span>#location块</span> root html; index index.html index.htm; } <span>#error_page 404 /404.html;</span><span># redirect server <span>error</span> pages to the static page /50x.html</span><span>#</span> error_page <span>500</span><span>502</span><span>503</span><span>504</span> /<span>50</span>x.html; location = /<span>50</span>x.html { <span>#location块</span> root html; } <span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># proxy_pass http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># root html;</span><span># fastcgi_pass 127.0.0.1:9000;</span><span># fastcgi_index index.php;</span><span># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;</span><span># include fastcgi_params;</span><span>#}</span><span># deny access to .htaccess files, <span>if</span> Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span># deny all;</span><span>#}</span> } <span># another virtual host using mix of IP-, name-, and port-based configuration</span><span>#</span><span>#server { #server块</span><span># listen 8000;</span><span># listen somename:8080;</span><span># server_name somename alias another.alias;</span><span># location / { #location块</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span><span># HTTPS server</span><span>#</span><span>#server {</span><span># listen 443 ssl;</span><span># server_name localhost;</span><span># ssl_certificate cert.pem;</span><span># ssl_certificate_key cert.key;</span><span># ssl_session_cache shared:SSL:1m;</span><span># ssl_session_timeout 5m;</span><span># ssl_ciphers HIGH:!aNULL:!MD5;</span><span># ssl_prefer_server_ciphers on;</span><span># location / {</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span>}</code>
From the configuration file we can summarize as follows
The nginix.conf configuration consists of three blocks: global block, events block and http block. The http block contains multiple server blocks, and each server block can contain multiple location blocks.
The meaning of each module in the configuration file
Global block
The global block is part of the default configuration file from the beginning to the events module. Mainly set the configuration instructions that affect the overall operation of the Nginx server. The scope of this instruction is the global Nginix server.
Usually includes the user (group) running the Nginx server, the number of worker processes allowed for production, Nginix process Pid storage path, log storage path and type, and configuration file introduction, etc.
events block
events block The instructions involved mainly affect the network connection between the Nginx server and the user. Commonly used configurations are:
Whether to enable serialization of network connections under multiple worker processes;
Whether to allow multiple network connections to be accepted at the same time;
Which event model to choose to handle connection requests;
The maximum number of connections that each worker process can support simultaneously, etc.
This part of the instructions has a great impact on the performance of the Nginix server. In the actual configuration, it should be flexibly adjusted according to the actual situation.
http block
http block is an important part of Nginix server configuration. Most functions of proxy, cache and log definitions and the configuration of third-party modules can be placed in this module. The main configuration in the http global block is as follows:
File introduction;
MIME-TYPE definition;
Log customization;
Whether to use sendfile to transfer files;
Connection timeout;
Number of single connection requests online, etc.
server block
server block is closely related to the concept of "virtual host". Each server block can be equivalent to a virtual host. The scope of the server block is this server block and will not affect other server blocks. Like the http block, the server block can also contain its own global block and multiple location blocks. The two main configurations of the server global block are as follows:
Monitoring configuration of virtual host;
The name or IP configuration of the virtual host
location block
Each server block can contain multiple location blocks. Strictly speaking, location is actually an instruction of the server block. The main function is to match the request string received by the Nginx server, match the string except the virtual host name, and process the specific request. Functions such as address direction, data caching, and response control are all implemented in this part.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above has introduced a detailed explanation of the basic configuration of the Nginx server, including nginx and server aspects. I hope it will be helpful to friends who are interested in PHP tutorials.