1. Open the nginx configuration file nginx.conf, and you can find that its initial content is as follows:
#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; proxy_pass http://192.168.56.202:8080; } #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
... #全局块 events #event块 { ... } http #http块 { ... #http全局块 } server #server块 { ... #server全局块 location [PATTERN] #location块 { ... } location [PATTERN] #location块 { ... } } server #server块 { ... } ... }
Global block: main settings Some configurations that affect the overall operation of the server have a global scope. Usually includes the user of the server
, the worker process allowed to be generated (this configuration item is generally the core number of the server host), the storage path of the nginx process pid
, the storage path and type of the log, and the introduction of the configuration file
events block : Mainly set some parameters that affect the network connection between the server and the user. Commonly used ones include: whether to enable serialization of network connections under
multiple worker processes, the master allows receiving multiple network connections at the same time, and each
worker process can simultaneously The maximum number of connections supported.
http block: Most of the general configuration proxy, cache, log definition and other functions and third-party configurations are set in this module
server block: related to the virtual host
location block: for requests Processing, address targeting, response control
The above has introduced the nginx configuration file-nginxconf for the first time, including the content of nginx and configuration files. I hope it will be helpful to friends who are interested in PHP tutorials.