title: Upstream timed out (uWSGI + NGINX + Flask)
body: <p>I have the following stack for my application: </p>
  
  <ol>
  <li>NGINX (1.4.6) </li>
  <li>uWSGI (1.9.17.1-debian (64bit)) </li>
  <li>Flask  </li>
  <li>Python 3.4</li>
  </ol>
  
  <p><strong>The Problem</strong>
  After NGINX restart all works well for a period(few minutes). After that period I receive a "504 Gateway Time-out" error. </p>
  
  <p><strong>NGINX log:</strong> </p>
  
  <blockquote>
    <p>*13 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 86.123.39.44, server:
    app.fc.com, request: "GET /dashboard/overview HTTP/1.1", upstream:
    "uwsgi://127.0.0.1:8001", host: "app.fc.com", referrer:
    "<a href="http://app.fc.com/dashboard/overview" rel="nofollow noreferrer">http://app.fc.com/dashboard/overview</a>"</p>
  </blockquote>
  
  <p><strong>uWSGI log:</strong></p>
  
  <blockquote>
    <p>app.fc.com [pid: 100017|app: 0|req: 103/219] 86.123.39.44 () {44 vars
    in 859 bytes} [Fri Mar  9 06:24:22 2018] GET /login => generated 245
    bytes in 1 msecs (HTTP/1.1 302) 3 headers in 131 bytes (1 switches on
    core 1)</p>
  </blockquote>
  
  <p><strong>My NGINX configuration is:</strong></p>
  
  <pre><code>server {
          listen 80;
          listen [::]:80;
  
          root /var/www/fc/website;
          index index.html index.htm index.php;
  
          # Make site accessible from http://localhost/
          server_name app.fc.com;
  
          location / {
                  sendfile        on;
                  client_max_body_size 20M;
                  keepalive_timeout  0;
  
                  proxy_connect_timeout   10;
                  proxy_send_timeout      15;
                  proxy_read_timeout      20;
  
                  include uwsgi_params;
                  uwsgi_pass 127.0.0.1:8001;
                  #uwsgi_read_timeout 30;
                  #uwsgi_send_timeout 30;
                  uwsgi_connect_timeout 60;
                  uwsgi_ignore_client_abort on;
          }
  }
  </code></pre>
  
  <p><strong>My uWSGI configuration is:</strong></p>
  
  <pre><code>[uwsgi]
  vhost = true
  socket = :8001
  #wsgi-file = /var/www/app.fc.com/reviewApp/wsgi.py
  wsgi-file = /var/www/fc/app/wsgi.py
  callable = app
  processes = 2
  threads = 4
  chdir = /var/www/fc/app/
  
  pythonpath = /var/www/fc/app/
  pythonpath = /var/www/py3/lib/python3.4
  virtualenv = /var/www/py3
  plugins = python3
  </code></pre>
  
  <p>Usually, the response to my request last under 5 seconds</p>