apache/nginx 和 django 如何在 404 错误方面很好地协同工作?
这是我们设置的简化版本:
- Nginx 反向代理前端提供静态文件
- Apache + mod_wsgi 为 /store 中的 django 应用程序提供服务,而 wordpress 对于
/store 之外的所有其他 URL 404 错误工作正常(通过 apache 404 处理程序)。
然而,/store 中的 404 错误命中了 django 404.html。我真的不想在该文件中重复自己(干!),因此希望 apache(或 nginx,我不挑剔)在整个站点上处理 404 错误。
我对 nginx 完全陌生,对 django 也比较陌生,并且多年来有一些破解 WordPress 和 apache 的经验。
谢谢
Here is a simplified version of our setup:
- Nginx reverse proxy front end serving static files
- Apache + mod_wsgi serving a django app in /store and wordpress for all other URLs
404 errors outside /store work fine (via an apache 404 handler).
However, 404 errors within /store hit the django 404.html. I'd really like not to repeat myself within that file (DRY!) and so would love to have 404 errors handled by apache (or nginx, I'm not fussy) across the site.
I am completely new to nginx, relatively new to django and have a bit of experience hacking wordpress and apache around over the years.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以将 404 页面符号链接为
{django}/templates/404.html
you could always symlink your 404 page as
{django}/templates/404.html
我已经找出了我认为的“正确”方法,即设置:
WSGIErrorOverride On
在我的 Apache 虚拟主机中。这样看来就达到了Apache处理404错误的预期目的了。
I have worked out what I think is the "correct" way of doing this which is to set:
WSGIErrorOverride On
In my Apache vhost. This seems to achieve the desired goal of Apache handle the 404 errors.