I have a working nginx production server running a Django app, using uwsgi (set up with this tutorial).
nginx and uwsgi are communicating through a UNIX socket.
However, as soon as I turn DEBUG = False
in my Django settings, I get a 502 error. The nginx error log tells me:
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"
How can I prevent the socket connection from timing out, and why is DEBUG = False making this difference?
Thanks!
I found the solution that works for me. I had to specify hosts for ALLOWED_HOSTS list in django's settings.py
ALLOWED_HOSTS = ['example.com', 'example.dev']
The "ALLOWED_HOSTS" answer also solved my problem. One thing to elaborate on, since it was not immediately clear to me anyways, the values you put here are the potential domain names (IPs, etc) that your site will be accessed by.
If your site is http://mysite.here/ then you NEED to put "mysite.here" in the ALLOWED_HOSTS list. Apparently, with Debug=True there is no HOST validation, once it is switched to False the system starts rejecting any request where the value of HOST: header does not appear in the list. For further reading:
https://docs.djangoproject.com/en/1.10/ref/settings/