nginx configuration file description # nginx running username user nginx; # nginx starts the process, usually set to be equal to the number of cpu, here is automatic worker_processes auto; # errorlog file location error_log / var / log /nginx/error. log ; # pid file address, records the pid of nginx, which is convenient for process management pid /run/nginx. pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. #Configurations used to load other dynamic modules include /usr/share/nginx/modules /* .conf; # Working mode and connection limit events { # Maximum number of concurrent connections per worker_processes # Total concurrency: worker_processes*worker_connections worker_connections 1024; } # Some configuration parameters related to providing http services are similar to mail http { # Set the format of the log 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 records the accessed user, page, browser, ip and other access information access_log /var/log/nginx/access.log main; # This part will be explained separately below # Set whether nginx uses the sendfile function to output files sendfile on; # Send the packet when the packet is the largest (using the Nagle algorithm) tcp_nopush on; # Send packets immediately (disable Nagle algorithm) tcp_nodelay on; # link timeout keepalive_timeout 65; # I don't know about this either... types_hash_max_size 2048; # Introduce file extension and file type mapping table include /etc/nginx/mime.types; # Default file type default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; # Several virtual hosts are supported on the http service. # A corresponding server configuration item for each virtual host # The configuration item contains the configuration related to the virtual host. server { # port listen 80 default_server; listen [::]:80 default_server; # Visited domain name server_name _; # Default website root directory (www directory) root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; # default request location / { } # Error page (404) error_page 404 /404.html; location = /40x.html { } # Error page (50X) error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
Key points
1. Regarding error_log, you can set the type of log (what level of information to record): debug, info, notice, warn, error, crit
2. About
the general network transmission process of sendfile
Hard disk >> kernel buffer >> user buffer >> kernel socket buffer >> protocol stack
After using sendfile,
hard disk >> kernel buffer (quick copy to kernelsocket buffer) >> protocol stack
can significantly improve the transmission performance.
3. tcp_nopush and tcp_nodelay
tcp_nopush only works when sendfile is
enabled. After tcp_nopush is enabled, the program will not send the data packet immediately after receiving it, but will wait for the maximum data packet to be sent at one time, which can relieve network congestion. (Nagleization)
In contrast, tcp_nodelay sends out packets immediately.
server { listen 80 default_server; listen [::]:80 default_server; # This is changed, you can also write your domain name server_name 192.168.17.26; # Default website root directory (www directory) root /var/www/; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { # The name of the home page index file is changed here index index.php index.html index.htm; } error_page 404 /404 .html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } # The newly added # PHP script requests are all forwarded to FastCGI for processing. The default configuration of the FastCGI protocol is used. # The protocol for communication between the Fastcgi server and the program (PHP, Python). location ~ \.php$ { # Set the listening port fastcgi_pass 127.0.0.1:9000; # Set the default home page file of nginx (it has been set above and can be deleted) fastcgi_index index.php; # Set the path of the script file request fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # Introduce the configuration file of fastcgi include fastcgi_params; } }