keepalive_timeout
http has a keepalive mode, which tells the webserver to keep the tcp connection open after processing a request. If it receives other requests from the client, the server will use this unclosed connection without establishing another connection.
http keep-alive, every request for a web page is http (pictures, css, etc.), and to open an http request, you need to establish a tcp connection first, and if a page has to open and close a request for each request TCP connections will cause a waste of resources. keepalive_timeout is the time that when an HTTP request is completed, its TCP connection will remain. If there is another HTTP request at this time, the TCP connection will be reused. If there are no new requests Come over before closing its tcp connection
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; client_max_body_size 8192m; #gzip on; #include /etc/nginx/conf.d/*.conf; server { listen 80 so_keepalive=30m::; listen 443 default ssl; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/portalkey.key; #ssl_password_file /etc/nginx/ssl/ssl.pass; ssl_session_timeout 5m; ssl_protocols sslv2 sslv3 tlsv1; ssl_ciphers high:!anull:!md5; ssl_prefer_server_ciphers on; location / { proxy_request_buffering off; proxy_pass http://127.0.0.1:8011/; proxy_connect_timeout 180; proxy_send_timeout 180; proxy_read_timeout 180; send_timeout 180; } location /test1_url/ { proxy_pass http://127.0.0.1:8008/; proxy_connect_timeout 180; proxy_send_timeout 180; proxy_read_timeout 180; send_timeout 180; } location /test2_url/ { proxy_pass http://127.0.0.1:3000/; proxy_connect_timeout 180; proxy_send_timeout 180; proxy_read_timeout 180; send_timeout 180; } } }
# Configuration section: http, default 75s
keepalive_timeout 60;
send_timeout: Send data to the client Client timeout, default is 60s. If the client does not receive 1 byte within 60 consecutive seconds, the connection is closed
proxy_connect_timeout: The connection timeout between nginx and upstream server
proxy_read_timeout: nginx receives upstream server data timeout, default is 60s, if 1 byte is not received within 60 consecutive seconds, the connection is closed
proxy_send_timeout: nginx sends Timeout for data to upstream server, default is 60s. If 1 byte is not sent within 60 consecutive seconds, the connection is closed
so_timeout:
When the user and server enable tcp connection --> This connection has no traffic for a long time (so_keepalive timeout) --> The server sends a detection packet to see if the user still exists --> If the detection packet is not returned, close the tcp connection
so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]
so_keepalive=30m::10 will set the idle timeout (tcp_keepidle) to 30 minutes, leave the probe interval (tcp_keepintvl) at its system default, and set the probes count (tcp_keepcnt) to 10 probes.
Only one of the above three parameters can be used, and cannot be used at the same time, such as so_keepalive=on, so_keepalive=off or so_keepalive=30s:: (meaning waiting for 30s without data packets to send detection packets)
The above is the detailed content of How to configure Nginx timeout timeout. For more information, please follow other related articles on the PHP Chinese website!