NGINX Basic module and configuration, NGINX module configuration
I. NGINX built-in Basic module 1, NGINX kernel module 2, EVENTS Module 3, HTTP Core Module 2, NGINX basic configuration file
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }}
Iii. NGINX kernel module
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;
This module is used to control the basic functions of the NGINX server.
Iii. EVENT Module
events { worker_connections 1024;}
This module is mainly used to control how NGINX processes connections. Some command parameters of this module will have an important impact on the performance of the application. Therefore, you need to exercise caution when setting this module. 4. HTTP Core Module
http { ...}
This module implements the HTTP service processing function of the NGINX server, which may be one of the most commonly used modules by developers. 1. Basic commands
http { server { ... }}
Server: used to configure virtual hosts. An http code segment can contain multiple server commands and configure multiple virtual hosts.
http { upstream mysvr { server 192.168.8.1x:80 weight=5; server 192.168.8.2x:80 weight=1; server 192.168.8.3x:80 weight=6; } server { ... location / { proxy_pass http://mysvr } ... }}
Upstream: NGINX Load Balancing
2. How does NGINX select a SERVER virtual host?
NGINX compares the HTTP request header with each server segment in the NGINX configuration file, and selects the first server segment to be matched.
The matching process is handled as follows:
1. Full domain name, static domain name match
2. Start with a wildcard domain name, for example, * .xxx.com.
3. the end part uses a wildcard domain name, for example, www. xxx .*
4. domain names with regular expressions
If no matching domain name is found, continue to select a server in the configuration file in the following order:
1. The section marked as [default | default_server] matching the listen command
2. Match the first server section of the listen command (or the listen 80 is implicitly included ).