带有 gunicorn 和 nginx 的 Django 没有 return 404 或 500
Django with gunicorn and nginx does not return 404 or 500
如果我使用 get_object_or_404()
,Django 会显示正确的错误页面,但 NGINX 仍然 returns:
HTTP/1.1 200 OK
Server: nginx
tl;tr
每页 returns 200 或(如果 500)超时。这里有什么问题吗?
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'
您应该设置处理程序,这可以通过以下方式完成:
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')
我已经在我的 urls.py 中完成了,但它也可以在 s
中完成
如果我使用 get_object_or_404()
,Django 会显示正确的错误页面,但 NGINX 仍然 returns:
HTTP/1.1 200 OK
Server: nginx
tl;tr
每页 returns 200 或(如果 500)超时。这里有什么问题吗?
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'
您应该设置处理程序,这可以通过以下方式完成:
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')
我已经在我的 urls.py 中完成了,但它也可以在 s
中完成