大网数据广告活动
服务器运维问答

Apache ErrorDocument without redirect?

· 52CE 我爱测

I have an Apache server that has / forwarding to a Tomcat server. When the Tomcat server is down, I want to display an error message. Here's what I have currently: ErrorDocument 502 "We're down, sorry :(" I would like to show a r…

问题原文

原帖链接 · Chris Smith · CC BY-SA 3.0

I have an Apache server that has / forwarding to a Tomcat server. When the Tomcat server is down, I want to display an error message. Here's what I have currently:

ErrorDocument 502 "We're down, sorry :("

I would like to show a relatively rich document (funny picture and stuffs), not just a one sentence message. The issue is, it doesn't appear I can serve documents, only redirect to them. I'm looking at this documentation.

I'd like to keep the same URL, but serve a different HTML file. Any way to do this?

<VirtualHost *:443>
        ServerName ${DOMAIN_NAME}
        ProxyRequests Off

        ProxyAddHeaders On

        ProxyPass /stomp http://tomcat:8080/stomp
        ProxyPassReverse /stomp http://tomcat:8080/stomp

        ProxyPass /.well-known http://mail.${DOMAIN_NAME}:80/.well-known
        ProxyPassReverse /.well-known http://mail.${DOMAIN_NAME}:80/.well-known

        ProxyPassMatch / http://tomcat:8080 retry=0 timeout=10
        ProxyPassReverse / http://tomcat:8080

        SSLCertificateFile /etc/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/${DOMAIN_NAME}/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        ErrorDocument 502 ${PROXY_ERROR_MESSAGE}
        ErrorDocument 503 ${PROXY_ERROR_MESSAGE}
</VirtualHost>

已采纳解答

原帖链接 · Unbeliever · CC BY-SA 3.0

If you specific a fully qualified URL for an error document you are implicitly causing a redirect because the browser must be told to "go get the error page somewhere else". However if you do something like:

ErrorDocument /errors/my503.html

The there will be no redirect as long as that URI path is served directly in apache. In your setup because you are proxying '/', you must explicity exclude that document from being proxied back to tomcat like this:

ProxyPass /errors/my503.html !
ErrorDocument /errors/my503.html

You also need to add exclusions for any page components used in the HTML.

If you want to serve custom error pages from actual HTTP error codes that come from tomcat (4xx codes normally), then you should look at the ProxyErrorOverride directive

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。