nginx timeout setting

nginx commonly used timeout configuration instructions

client_header_timeout

Syntax client_header_timeout time
Default value 60s
Context http server
description Specifies the timeout time for waiting for the client to send a request header (for example: GET / HTTP/1.1). Only when a request header is not received in one read, it will be counted as a timeout. If the client does not send anything within the timeout period, nginx returns HTTP status code 408 ("Request timed out")

client_body_timeout
syntax client_body_timeout time
default value 60s
context http server location
Description This directive sets the read timeout time of the request body. A timeout is set only when the request body is not obtained in a readstep. After timeout, nginx returns HTTP status code 408 ("Request timed out")

keepalive_timeout
syntax keepalive_timeout timeout [ header_timeout ]
default value 75s
context http server location
description The first parameter specifies the keep-alive connection timeout time with the client. The server will close the connection after this time. The optional second parameter specifies the time value in the Keep-Alive: timeout=time response header. This header can cause some browsers to actively close the connection, so that the server does not have to close the connection. Without this parameter, nginx will not send the Keep-Alive response header (although this header is not used to determine whether the connection is "keep-alive")
. The value of the two parameters can be different.
Note how different browsers handle "keep-alive" Header
MSIE and Opera ignore the "Keep-Alive: timeout=" header.
MSIE keeps the connection alive for about 60-65 seconds, then sends TCP RST
Opera keeps the connection alive forever
Mozilla keeps the connection alive for N plus about 1-10 seconds.
Konqueror keeps Long connection N seconds

lingering_timeout
syntax lingering_timeout time
default value 5s
context http server location
Description After lingering_close takes effect, before closing the connection, it will detect whether there is data sent by the user to the server, if no data is readable after the lingering_timeout time, close the connection directly; otherwise, The connection must not be closed until the data on the connection buffer has been read and discarded.

resolver_timeout
syntax resolver_timeout time
default value 30s
context http server location
Description This directive sets the DNS resolution timeout time

proxy_connect_timeout
syntax proxy_connect_timeout time
default value 60s
context http server location
Description This directive sets the connection timeout time with the upstream server, it is necessary to remember that this timeout cannot exceed 75 seconds.
This is not the time to wait for the backend to return the page, that is declared by proxy_read_timeout. If your upstream server is up, but hanging (for example, there are not enough threads to handle the request, so put your request in the request pool and process it later), then this statement is useless, due to the upstream server The connection has been established.

proxy_read_timeout
syntax proxy_read_timeout time
default value 60s
context http server location
Description This directive sets the read timeout time with the proxy server. It determines how long nginx will wait for a response to the request. This time is not the time to obtain the entire response, but the time of two reading operations.

proxy_send_timeout
syntax proxy_send_timeout time
default value 60s
context http server location
Description This specification sets the timeout time for sending requests to the upstream server. The timeout is not set for the entire send period, but between the two write operations. If the upstream does not receive new data after the timeout, nginx will close the connection

proxy_upstream_fail_timeout (fail_timeout)
syntax server address [fail_timeout=30s] The
default value is 10s. The
context upstream
indicates the parameters of the server instruction under the Upstream module. After setting a certain upstream backend fails a specified number of times (max_fails), the backend is inoperable. Default is 10 seconds

example:

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset utf-8;   

    #######
    ## http setting
    #######
    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;
    keepalive_timeout  100;           #这个参数表示http连接超时时间,默认是65s。要是上传文件比较大,在规定时间内没有上传完成,就会自动断开连接!所以适当调大这个时间。         
    fastcgi_connect_timeout 6000;
    fastcgi_send_timeout 6000;
    fastcgi_read_timeout 6000;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 8 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    ##
    client_header_timeout 120s;        #调大点
    client_body_timeout 120s;          #调大点
    client_max_body_size 100m;         #主要是这个参数,限制了上传文件大大小
    client_body_buffer_size 256k;   

    ## support more than 15 test environments
    server_names_hash_max_size 512;
    server_names_hash_bucket_size 128;

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
    gzip_vary on;



[root@dev-huanqiu ~]#  cat /Data/app/nginx/conf/vhosts/admin.wangshibo.conf
server {
        listen       80;

        server_name  admin.wangshibo.com;


        #if ($http_x_forwarded_for !~ ^(14.165.97.54|123.110.186.128|123.110.186.68)) {
        #   rewrite ^.*$  /maintence.php last;
        #}

        access_log  /var/log/wangshibo.log  main;


       location   / {
          proxy_pass http://127.0.0.1:8484/;
          proxy_connect_timeout   300;         #这三个超时时间适量调大点      
          proxy_send_timeout      600;        
          proxy_read_timeout      600;
          proxy_set_header X-Real-IP $remote_addr;    # 获取客户端真实IP
          proxy_set_header REMOTE-HOST $remote_addr;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # 获取代理者的真实ip
          proxy_set_header X-Forwarded-Scheme  $scheme;    # 解决getScheme,isSecure,sendRedirect
          proxy_buffer_size       32k;
          proxy_buffers           32 256k;
          proxy_busy_buffers_size 512k;
          proxy_temp_file_write_size 512k;
        }

      location   /static/video {
         root  /Data/app/tomcat-7-admin-wls/static/video;
        }

    } ##end server

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325388383&siteId=291194637