title: nginx, uwsgi, DJango, 502 when DEBUG=False, "upstream prematurely closed connection"
body: <p>I have a working nginx production server running a Django app, using uwsgi (set up with <a href="http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html" rel="nofollow">this tutorial</a>).</p>
  
  <p>nginx and uwsgi are communicating through a UNIX socket.</p>
  
  <p>However, as soon as I turn <code>DEBUG = False</code> in my Django settings, I get a 502 error.  The nginx error log tells me:</p>
  
  <pre><code>2015/09/08 10:37:51 [error] 940#0: *4 upstream prematurely closed connection while reading response header from upstream, client: myIP, server: mydomain.ca, request: "GET /quests/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/hackerspace.sock:", host: "myDomain"
  </code></pre>
  
  <p>How can I prevent the socket connection from timing out, and why is DEBUG = False making this difference?</p>
  
  <p>Thanks!</p>