1

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!

3
  • Have you checked the uwsgi log? Commented Sep 9, 2015 at 3:16
  • Any success with the error ? Commented Aug 19, 2016 at 15:17
  • @Lukasz no, but I'm going to take another stab at getting out of Debug mode next week and will report back with a solution if I find one. Commented Aug 19, 2016 at 16:48

2 Answers 2

1

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']

Sign up to request clarification or add additional context in comments.

Comments

0

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.