title: Gunicorn and Nginx: 504 Gateway Time-Out
body: <p>I'm running a Flask application using gunicorn and nginx on an Ubuntu server however I'm receiving a 504 Gateway Time-Out error when I load the page. This is how I've set the application up following <a href="https://exploreflask.com/deployment.html" rel="nofollow">this</a>:</p>
  
  <p>I have a file named <code>app</code> in <code>/etc/nginx/sites-available/</code> with the following contents:</p>
  
  <pre><code># Redirect www.psflask.net to psflask.net
  server {
          server_name www.psflask.net;
          rewrite ^ http://psflask.net/ permanent;
  }
  
  # Handle requests to psflask.net on port 80
  server {
          listen 80;
          server_name psflask.net;
  
                  # Handle all locations
          location / {
                          # Pass the request to Gunicorn
                  proxy_pass http://127.0.0.1:8000;
  
                  # Set some HTTP headers so that our app knows where the
                  # request really came from
                  proxy_set_header Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          }
  }
  </code></pre>
  
  <p>I created a symlink using:</p>
  
  <pre><code>sudo ln -s /etc/nginx/sites-available/psflask.net /etc/nginx/sites-enabled/psflask.net
  </code></pre>
  
  <p>and then I restart nginx with <code>sudo service nginx restart</code></p>
  
  <p>I run gunicorn with:</p>
  
  <pre><code>gunicorn run:app -p psflask.pid -D
  </code></pre>
  
  <p>I try to access the page however, it takes a while to load and then I get a 504 Gateway Time-Out error. What is the issue? Thanks.</p>
  
  <p>Edit:</p>
  
  <pre><code>* Rebuilt URL to: http://127.0.0.1:5000/
  * Hostname was NOT found in DNS cache
  *   Trying 127.0.0.1...
  * Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
  &gt; GET / HTTP/1.1
  &gt; User-Agent: curl/7.35.0
  &gt; Host: 127.0.0.1:5000
  &gt; Accept: */*
  &gt; 
  * HTTP 1.0, assume close after body
  &lt; HTTP/1.0 200 OK
  &lt; Content-Type: text/html; charset=utf-8
  &lt; Content-Length: 125
  &lt; Server: Werkzeug/0.10.4 Python/2.7.6
  &lt; Date: Sat, 19 Sep 2015 14:43:37 GMT
  &lt; 
  &lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;Home - microblog&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
      &lt;h1&gt;Hello, welcome to my site.&lt;/h1&gt;
   &lt;/body&gt;
  * Closing connection 0
  </code></pre>