title: upstream timed out error in Python Flask web app using Fabric on nginx
body: <p>I have my Python Flask web app hosted on nginx. While trying to execute a request it shows a timeout error in the nginx error log as shown below :</p>
  
  <blockquote>
    <p>[error] 2084#0: *1 upstream timed out (110: Connection timed out)
    while reading response header from     upstream, client:
    192.168.2.224, server: 192.168.2.131, request: "POST /execute HTTP/1.1", upstream: "uwsgi://unix:/hom<br>
    e/jay/PythonFlaskApp/app.sock", host: "192.168.2.131:9000", referrer:
    "<a href="http://192.168.2.131:9000/" rel="nofollow">http://192.168.2.131:9000/</a>"</p>
  </blockquote>
  
  <p>If I try to run the app locally it works fine and responds fine.
  Any one have any idea what might be wrong ? </p>
  
  <p>the error found in browser console is :</p>
  
  <blockquote>
    <p>Gateway Time-out</p>
  </blockquote>
  
  <p>Here is the nginx config file:</p>
  
  <pre><code>server {
      listen 9000;
      server_name 192.168.2.131;
  
      location / {
          include uwsgi_params;
          proxy_read_timeout 300;
          uwsgi_pass unix:/home/jay/PythonFlaskApp/app.sock;
      }
  }
  </code></pre>
  
  <p>And here is the Python <a href="http://www.fabfile.org/" rel="nofollow">Fabric</a> code that i trying to execute. i'm not sure if this is causing the issue, but any waz here is the code :</p>
  
  <pre><code>from fabric.api import *
  
  @application.route("/execute",methods=['POST'])
  def execute():
      try:
          machineInfo = request.json['info']
          ip = machineInfo['ip']
          username = machineInfo['username']
          password = machineInfo['password']
          command = machineInfo['command']
          isRoot = machineInfo['isRoot']
  
          env.host_string = username + '@' + ip
          env.password = password
          resp = ''
          with settings(warn_only=True):
              if isRoot:
                  resp = sudo(command)
              else:
                  resp = run(command)
  
          return jsonify(status='OK',message=resp)
      except Exception, e:
          print 'Error is ' + str(e)
          return jsonify(status='ERROR',message=str(e))
  </code></pre>
  
  <p>I have a uWSGi config file for the web app and started it using an upstart script. Here is uwSGi conf file : </p>
  
  <pre><code>[uwsgi]
  module = wsgi
  
  master = true
  processes = 5
  
  socket = app.sock
  chmod-socket = 660
  vacuum = true
  
  die-on-term = true
  </code></pre>
  
  <p>and here is upstart script</p>
  
  <pre><code>description "uWSGI server instance configured to serve Python Flask App"
  
  start on runlevel [2345]
  stop on runlevel [!2345]
  
  setuid jay
  setgid www-data
  
  chdir /home/jay/PythonFlaskApp
  exec uwsgi --ini app.ini
  </code></pre>
  
  <p>I have followed the below tutorial on <a href="https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04" rel="nofollow">running flask app on nginx</a></p>