在 CentOS 系统中,要自定义 Apache2(实际上在 CentOS 中称为 httpd)的错误页面,请按照以下步骤操作:
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
/var/www/html)下创建一个新的 HTML 文件,例如 custom_error.html。使用你喜欢的文本编辑器编辑该文件,添加你想要显示的自定义错误信息。例如:
<!DOCTYPE html>
<html>
<head>
    <title>自定义错误页面</title>
</head>
<body>
    <h1>抱歉,我们遇到了一个问题。</h1>
    <p>请稍后再试,或者联系我们的支持团队以获取帮助。</p>
</body>
</html>
/etc/httpd/conf/httpd.conf 或 /etc/httpd/conf.d/ 目录下的某个文件)中,找到或添加以下内容:ErrorDocument 400 /custom_error.html
ErrorDocument 401 /custom_error.html
ErrorDocument 403 /custom_error.html
ErrorDocument 404 /custom_error.html
ErrorDocument 500 /custom_error.html
这里,我们将常见的错误代码(如 400、401、403、404 和 500)映射到我们之前创建的自定义错误页面。你可以根据需要修改这些错误代码和对应的文件路径。
sudo systemctl restart httpd
现在,当用户遇到指定的错误代码时,Apache 将显示你的自定义错误页面。