How to return an apache error page from a wsgi app

2019-03-30 17:21发布

I have a simple working wsgi app. I can successfully return whatever HTTP status code, headers, and HTML I want. What I would like to do, is that when I'm returning a status code other than '200 OK', for WSGI to let apache fall back to its error handling and display whatever page apache is configured to display according to its 'ErrorDocument' setting.

For example, this works fine when my WSGI app crashes unintentionally, then I see the default 'internal server error' page from apache.

My question is, how can I do this in a controlled, deliberate manner? For example, I can then do my own authentication, and fallback to the default apache page I have set up.

Any ideas?

1条回答
不美不萌又怎样
2楼-- · 2019-03-30 17:50

Presuming you actually mean with mod_wsgi under Apache, ensure you are using mod_wsgi daemon mode and set:

WSGIErrorOverride On

There is a brief mention of this in mod_wsgi version 3.0 release notes.

http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300

If you are using Apache as proxy in front of distinct Python web server running WSGI application, then use Apache ProxyErrorOverride directive instead.

查看更多
登录 后发表回答