You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Apache环境下ErrorDocument自定义错误页面失效问题求助(含Certbot生成的Rewrite规则)

Ubuntu Apache环境下ErrorDocument自定义错误页面失效问题求助(含Certbot生成的Rewrite规则)

大家好,我现在碰到个头疼的问题——Apache的自定义错误页面(ErrorDocument)死活不生效。我翻了好多论坛帖子和教程试了各种办法都没用,目前能想到的和别人情况不一样的地方,就是我的配置里有Certbot自动加上的RewriteCond规则。

之前我在旧版本Ubuntu的自签名证书站点上成功配置过,但这次在Ubuntu 22.04上就不行了。

环境信息

  • 操作系统:Ubuntu 22.04

当前站点配置文件内容

ServerAdmin webmaster@localhost
ServerName leofriclegends.com
ServerAlias www.LeofricLegends.com www.leofriclegends.com LeofricLegends.com *.LeofricLegends.com *.leofriclegends.com 92.27.77.101
DocumentRoot /var/www/leofriclegends.com/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

ErrorDocument 405 /404.html
ErrorDocument 500 /WebPageError.html
ErrorDocument 502 /WebPageError.html
ErrorDocument 503 /WebPageError.html
ErrorDocument 504 /WebPageError.html

<Files "404.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/404.html$
</If>
</Files>

<Files "WebPageError.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/WebPageError.html$
</If>
</Files>

RewriteEngine on
RewriteCond %{SERVER_NAME} =*.LeofricLegends.com [OR]
RewriteCond %{SERVER_NAME} =leofriclegends.com [OR]
RewriteCond %{SERVER_NAME} =www.LeofricLegends.com [OR]
RewriteCond %{SERVER_NAME} =LeofricLegends.com [OR]
RewriteCond %{SERVER_NAME} =www.leofriclegends.com [OR]
RewriteCond %{SERVER_NAME} =92.27.77.101 [OR]
RewriteCond %{SERVER_NAME} =*.leofriclegends.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

apachectl -S输出结果

VirtualHost configuration:
*:443                  leofriclegends.com (/etc/apache2/sites-enabled/leofriclegends.com-le-ssl.conf:2)
*:80                   is a NameVirtualHost
	default server leofriclegendslimitedserver.home (/etc/apache2/sites-enabled/000-default.conf:1)
	port 80 namevhost leofriclegendslimitedserver.home (/etc/apache2/sites-enabled/000-default.conf:1)
	port 80 namevhost industrialdimensions.co.uk (/etc/apache2/sites-enabled/industrialdimensions.co.uk.conf:1)
		alias www.industrialdimensions.co.uk
		alias www.IndustrialDimensions.co.uk
		alias IndustrialDimensions.co.uk
		wild alias *.IndustrialDimensions.co.uk
		wild alias *.industrialdimensions.co.uk
	port 80 namevhost leofriclegends.com (/etc/apache2/sites-enabled/leofriclegends.com.conf:1)
		alias www.LeofricLegends.com
		alias www.leofriclegends.com
		alias LeofricLegends.com
		alias 92.27.77.101
		wild alias *.LeofricLegends.com
		wild alias *.leofriclegends.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

我已经查阅了不少相关的教程、官方文档和社区问答,但都没能解决这个问题。我肯定是漏掉了什么明显的配置点,或者因为Certbot生成的Rewrite规则需要额外的处理步骤。如果有大佬遇到过类似问题或者有解决思路,欢迎帮忙指点一下,非常感谢!

备注:内容来源于stack exchange,提问作者La Phyzz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 14:33:12