6

在问这个问题之前,我在谷歌和任何地方搜索了几个小时,试图增加 Varnish 4 和 Nginx 之间的连接超时,但没有找到解决方案。

所以这是我的清漆配置:

backend web1 {
    .host = "192.168.1.21";
    .port = "80";
    .probe = {
        .request =
        "HEAD / HTTP/1.1"
        "Host: localhost"
        "Connection: close";

        .timeout = 1s;
        .interval = 5s;
        .window = 5;
        .threshold = 3;
    }
    .connect_timeout = 300s;
    .between_bytes_timeout = 300s;
}

这是 Nginx 配置:

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 0; # wait for 5 minutes before timeout the request

#       proxy_connect_timeout   60s;
#       proxy_send_timeout      300s;
#       proxy_read_timeout      300s;

        fastcgi_read_timeout    300s;

        types_hash_max_size 2048;
        # server_tokens off;

        client_body_buffer_size 20m; #Buffer of post request
        client_header_buffer_size 2k; #Buffer of headers
        client_max_body_size 40m; #Max post request size
        large_client_header_buffers 20 2k; #Max number and size of buffers of large requests

        server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

我尝试了所有参数,但没有任何效果。

当我设置keepalive_timeout为 300s 时,如果我直接访问它,超时设置为 300s(5 分钟),但是当我通过 Varnish 访问时,超时设置为 60s。所以我禁用了 Nginxkeepalive_timeout并将其设置为 0,但遇到了同样的问题。

怎么了?

如何增加 Varnish 和 Nginx 之间的超时时间?

4

1 回答 1

4

作为这个问题的答案指出:https ://serverfault.com/questions/573169/varnish-503-error-after-exactly-60-seconds-how-to-change-this-timeout-value

问题似乎是.first_byte_timeoutVCL中的参数,默认只有60秒。

将第一个字节超时设置为 300 秒:

.first_byte_timeout = 300s;
于 2018-08-29T12:30:04.310 回答