title: Ngnix is very slow
body: <p>I configured ngnix but it is very slow. Sometimes when I hit reload assets are pending until it starts to download them. I noticed that after few consecutive reloads of the page it start to hang, pending assets and slows down.  Is there something wrong with my configuration? I deploy my app to Heroku and use ngnix in front.</p>
  
  <pre><code>daemon off;
  worker_processes &lt;%= ENV['NGINX_WORKERS'] || 4 %&gt;;
  
  worker_rlimit_nofile 10000;
  
  events {
    # optmized to serve many clients with each thread
      use epoll;
  
    # if accept_mutex is enabled, worker processes will accept new connections by turn. Otherwise, all worker processes will be notified about new connections, and if volume of new connections is low, some of the worker processes may just waste system resources.
      accept_mutex on;
  
      multi_accept    on;
  
      worker_connections 1024;
  }
  
  # error logs
  error_log   logs/nginx/error.log;
  error_log   logs/nginx/error_extreme.log emerg;
  error_log   logs/nginx/error_debug.log debug;
  error_log   logs/nginx/error_critical.log crit;
  
  
  http {
  
    charset   utf-8;
    include mime.types;
  
    default_type  application/octet-stream;
  
  
      log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
  
      access_log logs/nginx/access.log l2met;
  
  
      # # - Basic Settings
  
      sendfile        on;
      tcp_nopush      on;
      tcp_nodelay       on;
      types_hash_max_size       2048;
  
  
    # # - Enable open file cache
  
      open_file_cache max=1000 inactive=20s;
      open_file_cache_valid   30s;
      open_file_cache_min_uses    2;
      open_file_cache_errors  on;
  
  
      # # - Configure buffer sizes
  
      client_body_buffer_size 16k;
      client_header_buffer_size   1k;
  
  
      # # - Responds with 413 http status ie. request entity too large error if this value exceeds
  
      client_max_body_size    8m;
  
      large_client_header_buffers 2 1k;
  
  
      # # - Configure Timeouts
  
      client_body_timeout 12;
      client_header_timeout   12;
  
      # # - Use a higher keepalive timeout to reduce the need for repeated handshake
  
      keepalive_timeout   300;
  
      # # - if the request is not completed within 10 seconds, then abort the connection and send the timeout errror
  
      send_timeout    10;
  
  
      # # - Hide nginx version information
  
      server_tokens   off;
  
    # # - Dynamic gzip compression
      gzip                      on;
      gzip_http_version         1.0;
      gzip_disable              "msie6";
      gzip_vary                 on;
      gzip_min_length           20;
      gzip_buffers              4 16k;
      gzip_comp_level           3;
      gzip_proxied              any;
  
  
      #Turn on gzip for all content types that should benefit from it.
  
      gzip_types  application/ecmascript;
      gzip_types  application/javascript;
      gzip_types  application/json;
      gzip_types  application/pdf;
      gzip_types  application/postscript;
      gzip_types  application/x-javascript;
      gzip_types  image/svg+xml;
      gzip_types  text/css;
      gzip_types  text/csv;
      gzip_types  text/javascript;
      gzip_types  text/plain;
      gzip_types  text/xml;
  
      map $http_upgrade $connection_upgrade {
          default upgrade;
          '' close;
       }
     #proxying requests to other servers
       upstream nodebeats {
          server unix:/tmp/nginx.socket max_fails=3 fail_timeout=30s;
          keepalive   32;
       }
  
       server {
          listen       &lt;%= ENV['PORT'] %&gt;;
          server_name  _;
          root        "/app/";
  
  
          location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_http_version    1.1;
        proxy_set_header  Upgrade $http_upgrade;
        proxy_set_header  Connection "upgrade";
        proxy_pass http://nodebeats;
          }
  
      location ~* \.(js|css|jpg)$ {
        root                  "/app/src/dist";
        add_header            Pragma public;
        add_header            Cache-Control public;
        expires               1y;
        gzip_static           on;
        gzip                  off;
        gzip_http_version     1.0;
        gzip_disable        "msie6";
        gzip_vary             on;
        gzip_min_length       20;
        gzip_proxied          any;
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok. I found out what setting is causing this. It is <strong>proxy_read_timeout</strong> which is by default 60 seconds. If i put it to 1 second, i can reload page any number of times I want and it always refreshes quickly. But why?</p>
  
  <p>That is supposed to be time that nginx waits server to respond. If I get back response and reload the page, why does it stale? Isn't timeout supposed to be restarted and wait for response again?</p>