2016-07-15 62 views
1

如果我使用get_object_or_404(),Django的顯示了我正確的錯誤頁面,但NGINX仍然返回:的Django與gunicorn和nginx的不返回404或500

HTTP/1.1 200 OK 
Server: nginx 

TL,TR

每個頁面返回200或(如果500)超時。這裏有什麼問題?

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' 

回答

1

你應該設置的處理程序,這是可以做到這樣:

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