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.
alan
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?
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.
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.