问题描述
我正在尝试在Apache上设置自定义403和404错误页面.
I am trying to setup custom 403 and 404 error pages on Apache.
Server config is as follows:
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2019-04-03T13:22:37
Ubuntu 18.04.2 LTS
我将Apache用于AJP反向代理,如下所示:
I use Apache for AJP reverse proxy, as below:
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /app ajp://localhost:8009/share
ProxyPassReverse /app ajp://localhost:8009/share
我的ErrorDocument代码如下:
My ErrorDocument code is as below:
ErrorDocument 404 /cah-404.html
ErrorDocument 403 /cah-403.html
现在,如果我通过浏览器转到上述应用,例如" https://server.xyz/app",我会收到类似以下的消息:
Now if I go via browser to the above app, like "https://server.xyz/app", I get a message like the below:
Forbidden
You don't have permission to access /app/ on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.29 (Ubuntu) Server at server.xyz Port 443
我的自定义错误页面位于/var/www/html这些页面上的权限是444
My custom error pages are at /var/www/htmlPermission on those pages is 444
任何想法为何会发生此错误?我正在尝试从未经授权的ISP访问该页面.因此,禁止显示是很好的-但它应该显示自定义的禁止页面.
Any ideas why this error is happening?I am trying to access the page from an ISP that is not authorised. So it is fine that Forbidden is showing - but it should show the custom forbidden page.
推荐答案
我已使用以下方法解决了此问题: https://serverfault.com/questions/266924/当代理服务器关闭时,apache-reverse-proxy-error-page
I have resolved this using:https://serverfault.com/questions/266924/apache-reverse-proxy-error-page-when-proxied-server-is-down
答案的关键部分是您应该使用URL指向您的ErrorDocument,否则,如果您使用文件系统引用,则在尝试查找它时会得到另外的503."
The key part of the answer is "You should use a URL to point to your ErrorDocument otherwise if you use a filesystem reference you will get an additional 503 whilst trying to find it."
所以现在,我的errordocument指令看起来像:
So now, my errordocument directives look like:
ErrorDocument 404 http://server.xyz/cah-404.html
ErrorDocument 403 http://server.xyz/cah-403.html
这篇关于通过将AJP代理与Apache结合使用时,不显示“自定义错误"页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!