I have a problem with my current setup... And the issue is, that if i set DEBUG = False in django settings.py file nginx stops showing django tracebacks on 500 errors, but does not show our 500 page either. It just displays nginx 502 bad gateway error.

I do get the email error with traceback, just as i've configured it to mail tracebacks to me, when they occur. But i want to display nice 500 page to users not nginx 502 gateway error...

Honestly, i dont even know where to begin searching the root of the problem. Im prepared to post all necessary config files, if some nginx expert would come and tell me what he wants to see.


Edit1: I looked up what log file shows at one of those 500 errors, and it shows this:

[pid: 16203|app: 0|req: 1/1] my.ip.address () {46 vars in 915 bytes} [Thu Sep 12 10:01:17 2013] GET /settings/personal/ => generated 0 bytes in 1249 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

Does this mean that its somehow django fault cause it looks like django returned 0 bytes?


Does this mean that its somehow django fault cause it looks like django returned 0 bytes?

Yes, there is no nginx issue here, the problem is that Django returns nothing instead of a 500 error page.


Use nginx's error_page directive documented here

With that Nginx will intercept 5XX error from backend and show any page you like to the end user.

  • As i understand, that works when you have static error page where to redirect or show. django apps usually do not have dedicated 404 or 500 pages as 404 and 500 errors are shown on the pages they appear on. so i do not have something like 404.html or 500.html to show. – Zayatzz Sep 12 '13 at 8:32
  • Ok, if you want an error page shown by django - Nginx has nothing to do with that. – DukeLion Sep 12 '13 at 8:37
  • How can i do that though? If thats not nginx problem then what is the showstopper here? Specially since 404 pages are showing properly without that error_page setting. – Zayatzz Sep 12 '13 at 8:39

I recently had the same problem. What i did to fix this was to add to uwsgi startup parameters these: –catch-exceptions and –error-route-status=”500 file:filename=/usr/local/nginx/html/index.html,status=500 Internal Server Error”

One was to catch exceptions from django, even if DEBUG=false. and the other to redirect a request to a particular file so the client avoids seeing a page full of django exceptions, and instead see a “we are sorry blah blah” message. Keep in mind that the uwsgi version i'm using is 1.9.15.

  • One more thing, check that your uwsgi binary has the routing option enabled at compile time.For that you need the pcre-devel libraries installed.If not –error-route-status will not work. – Oskar Kossuth Sep 19 '13 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.