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

时间:2015-12-31 15:54:26

标签: nginx varnish-4

在提出这个问题之前,我在谷歌和世界各地搜索了几个小时,试图增加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。所以我禁用了Nginx keepalive_timeout并将其设置为0,但遇到了同样的问题。

怎么了?

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

1 个答案:

答案 0 :(得分:2)

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

问题似乎出在VCL中的.first_byte_timeout参数上,默认情况下只有60秒。

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

.first_byte_timeout = 300s;