wiesson
wiesson

Reputation: 6822

Django with gunicorn and nginx does not return 404 or 500

If I use get_object_or_404(), Django shows my correct error page but NGINX still returns:

HTTP/1.1 200 OK
Server: nginx

tl;tr

Every page returns 200 or (if 500) time out. Whats wrong here?

NGINX conf:

location / {
        proxy_pass http://unix:/opt/repo/page.sock;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
}

urls.py

from django.conf import settings

handler404 = 'my_app.views.page_not_found'

Upvotes: 1

Views: 455

Answers (1)

bknux
bknux

Reputation: 556

You should setup the handlers, this can be done this way:

from django.utils.functional import curry

handler404 = curry(page_not_found, template_name='404.html')
handler500 = curry(page_not_found, template_name='500.html')
handler403 = curry(page_not_found, template_name='403.html')

I have done this in my urls.py, but it also can be done in s

Upvotes: 1

Related Questions