title: How to increase timeout between Varnish 4 and Nginx
body: <p>Before asking this question, I searched Google and everywhere for hours trying to increase the connection timeout between Varnish 4 and Nginx but found no solution.</p>
  
  <p>So here is my Varnish Config:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>And this is Nginx config:</p>
  
  <pre><code>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/*;
  }
  </code></pre>
  
  <p>I tried all parameters but nothing works.</p>
  
  <p>When I set <code>keepalive_timeout</code> to 300s, if I access it directly, the timeout is set to 300s (5 minutes) but when I access through Varnish, timeout is set to 60s. So I disabled the Nginx <code>keepalive_timeout</code> and  setting it to 0, but got the same problem.</p>
  
  <p>What's wrong?</p>
  
  <p>How can I increase timeout between Varnish and Nginx?</p>