This is the 21st day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Nginx is a server-side load balancing proxy, Http proxy, and reverse proxy: one of the most commonly used features of Web servers, especially reverse proxies. As a reverse proxy, Nginx provides stable performance and flexible configuration of forwarding functions. Nginx can adopt different forwarding policies based on different re matches. This blogger has compiled a list of configuration options for your reference.

#user nobody; Configure the user or group. Default is nobody 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 {accept_mutex on; Worker_connections = on worker_connections 65535; # maximum number of connections, default is 512 multi_accept on; HTTP {include mime.types; Default_type application/octet-stream; # default file type, Default text/plain #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/acc.log main; #combined = default value sendFile on; Tcp_nopush on allows sendFile to be transferred in HTTP block, server block, location block. tcp_nodelay on; #keepalive_timeout 0; keepalive_timeout 65; Connect to FZJH (HTTP, server, location: upstream) {server 127.0.0.1:7878; 3333 backup server 192.168.10.121:; } server {listen 8000; Server_name localhost; Charset utF-8; #access_log logs/host.access.log main; Location / {# request url filtering, regular matching, ~ is case sensitive, ~* is case insensitive. #root path; # root directory #index vv.txt; Proxy_pass http://127.0.0.1:3000; Proxy_pass FZJH; # deny 127.0.0.1; # allow 172.18.5.54; # allowed IP} location /check_token {# request url filtering, regular matching, ~ is case sensitive, ~* is case insensitive. Proxy_pass http://127.0.0.1:8088; Proxy_redirect on; # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /logout {# request url filtering, regular match, ~ is case sensitive, ~* is case insensitive. Proxy_pass http://127.0.0.1:8088; Proxy_redirect on; proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; } location ~ \. Aaaa ${# request url filtering, regular matching, ~ is case sensitive, ~* is case insensitive. rewrite ^/([\w]+)/(.*)\.air$ /$2 break ; Proxy_pass http://127.0.0.1:8088; # proxy_redirect on; proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; } #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 {# error page 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; # #}}}Copy the code

2. Perform other configurations

  1. include mime.types; File extension and file type mapping table
  2. default_type application/octet-stream; The default file type is text/plain
  3. #access_log off; Cancel service log
  4. Log_format myFormat ‘remoteADDR – remote_ADDR – remoteADDR – remote_user [timelocal]time_local] timelocal] Request statusstatus statusbody_bytes_sent httprefererhttp_referer httprefererhttp_user_agent $http_x_forwarded_for’; # Custom format
  5. access_log log/access.log myFormat; #combined is the default value for logging format
  6. sendfile on; # allow sendFile transfer, default is off, HTTP block, server block, location block
  7. sendfile_max_chunk 100k; The number of transfers per call cannot exceed the set value. The default value is 0, that is, no upper limit is set.
  8. keepalive_timeout 65; # connection timeout, default is 75s, can be in HTTP, server, location block.
  9. proxy_connect_timeout 1; Nginx specifies the timeout period for the server to establish a connection with the proxied server
  10. proxy_read_timeout 1; # the elapsed time that the nginx server waits for a read request from the proxy server group. Default: 60 seconds.
  11. proxy_send_timeout 1; # the elapsed time that the nginx server waits for a write request from the proxy server group. The default is 60 seconds.
  12. Proxy_http_version 1.0; #Nginx server provides the proxy service with HTTP version 1.0, 1.1, default set to version 1.0.
  13. #proxy_method get; Support client request methods. Post/get;
  14. proxy_ignore_client_abort on; Whether the nginx server terminates a request to the proxy server when the client is disconnected. The default value is off.
  15. proxy_ignore_headers “Expires” “Set-Cookie”; #Nginx server does not handle HTTP header fields.
  16. proxy_intercept_errors on; # If the status code returned by the proxy server is 400 or greater, the error_page configuration takes effect. The default value is off.
  17. proxy_headers_hash_max_size 1024; # Maximum size of hash table for storing HTTP header. Default value: 512 characters.
  18. proxy_headers_hash_bucket_size 128; #nginx server request to store HTTP header hash table capacity. The default value is 64 characters.
  19. proxy_next_upstream timeout; The status value returned by the proxy server when the server group set up in the upstream fails. error|timeout|invalid_header|http_500|http_502|http_503|http_504|http_404|off
  20. #proxy_ssl_session_reuse on; The default is on, and you can set it to off if you find “SSL3_GET_FINSHED: Digest Check failed” in the error log.