为什么我的自定义Apache错误页面没有显示?

时间:2014-08-08 16:32:13

标签: apache mod-wsgi

我有一个在Apache2下运行的mod_wsgi应用程序,只要有未捕获的异常,就会显示默认的Apache HTTP 500错误页面,尽管我的Apache配置中有ErrorDocument 500 /500.html

我可以使用一些mod_wsgi指令来显示我的自定义错误页面吗?我不是在寻找可以放在我的mod_wsgi脚本中的东西,因为如果脚本中有错误,这将无济于事。

编辑2:使用以下配置时,浏览到/cgi-bin/test.wsgi会成功显示自定义错误页面,但浏览到/test会显示默认的Apache。

编辑:这是一个小样本配置,它给我带来了同样的问题:

的/ etc / apache2的/启用的站点 - /测试

<VirtualHost *:80>
    ServerName foo.example.com

    DocumentRoot /path/to/docroot/

    <Directory /path/to/docroot/>
        Order allow,deny
        Allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /path/to/docroot/cgi-bin/

    <Directory /path/to/docroot/cgi-bin/>
        Options +ExecCGI
        AddHandler wsgi-script .wsgi
        Order allow,deny
        Allow from all
    </Directory>

    ErrorDocument 500 /500.html

    WSGIDaemonProcess test user=www-data group=www-data processes=4 threads=1 display-name=%{GROUP}
    WSGIProcessGroup test
</VirtualHost>

/path/to/docroot/.htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^test/?$    /cgi-bin/test.wsgi/    [L,QSA]

/path/to/docroot/500.html

<html><body>This be 500.</body></html>

/path/to/docroot/cgi-bin/test.wsgi

hi

2 个答案:

答案 0 :(得分:0)

使用Apache配置时,URL /500.html映射到什么位置?

如果它没有映射到有效的URL,因此尝试针对它发出子请求会生成404,那么Apache将返回一个通用的500响应。

在您的访问日志中查看/500.html访问权限,看看它是否表示404。

答案 1 :(得分:0)

默认情况下,WSGI应用程序完全控制请求响应周期,因此将绕过任何Apache错误处理程序。

在Apache设置工作之前,您可能需要WSGIErrorOverride On指令。我自己还没有尝试过这个,但是在跟踪ops团队类似目标的建议时(当Django应用程序给出500时,Apache返回自己的静态错误页面)我通过How to return an apache error page from a wsgi app?和 - 来到了目标相反 - How to configure Apache with mod_wsgi so that error messages come from the application?

此功能的original description因为它被添加到mod_wsgi中而是:

  

在mod_proxy的情况下,存在ProxyErrorOverride指令,   这允许你说你想要后端生成的错误页面   应用程序在适当时被忽略,并允许Apache生成   内容通过其正常的ErrorDocument指令。

     

应该实现等效的WSGIErrorOverride指令以允许   WSGI应用程序更适合WSGI的大型站点   应用程序不是唯一的内容来源,而只是一个贡献者。

所以它听起来像我们追求的那样。请注意,这已添加到mod_wsgi 3.0及更高版本中,希望它们已经足够长时间以供常用。