/ / Django con gunicorn e nginx non restituisce 404 o 500 - python, django, nginx, http-status-code-404, gunicorn

Django con gunicorn e nginx non restituisce 404 o 500 - python, django, nginx, http-status-code-404, gunicorn

Se io uso get_object_or_404(), Django mostra la mia pagina di errore corretta ma NGINX restituisce ancora:

HTTP/1.1 200 OK
Server: nginx

tl; tr

Ogni pagina restituisce 200 o (se 500) timeout. Cosa c'è di sbagliato qui?

Conf NGINX:

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"

risposte:

1 per risposta № 1

Dovresti configurare i gestori, questo può essere fatto in questo modo:

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")

Ho fatto questo nel mio urls.py, ma può anche essere fatto in s