apache - apache 2.4 自定义错误响应不起作用
问题描述
我正在尝试为我的网站设置一个未找到的自定义 404 错误页面。我看过很多教程并阅读了这里的文档https://httpd.apache.org/docs/2.4/custom-error.html。
当我向我的域提供无效的 url 时,这是我得到的默认 404 页面。
Not Found
The requested URL /notreal was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
这是我的 httpd.conf 文件中允许覆盖的内容:
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/opt/bitnami/apache2/htdocs"
<Directory "/opt/bitnami/apache2/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
这是我的 .htaccess 文件:
Options -Indexes
ErrorDocument 404 /error/404.html
我有 .htaccess 文件/opt/bitnami/apache2/htdocs
以及/opt/bitnami/apache2/htdocs/error
我想用自定义 JS 和 CSS 输出的自定义 404.html 页面。
编辑:
Bitnami 配置文件:
# Default Virtual Host configuration.
<IfVersion < 2.3 >
NameVirtualHost *:80
NameVirtualHost *:443
</IfVersion>
<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
<Directory "/opt/bitnami/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
# Error Documents
ErrorDocument 503 /503.html
ErrorDocument 404 /error/404.html
# Bitnami applications installed with a prefix URL (default)
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>
# Default SSL Virtual Host configuration.
<IfModule !ssl_module>
LoadModule ssl_module modules/mod_ssl.so
</IfModule>
Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout 300
<VirtualHost _default_:443>
DocumentRoot "/opt/bitnami/apache2/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"
<Directory "/opt/bitnami/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
# Error Documents
ErrorDocument 503 /503.html
ErrorDocument 404 /error/404.html
# Bitnami applications installed with a prefix URL (default)
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>
# Bitnami applications that uses virtual host configuration
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"
解决方案
我让我的第 404 页开始工作。所以我阅读了文档,它说该页面需要位于根目录中。/opt/bitnami/apache2/htdocs
.
它可以在那里,但对于我的问题,我有一个指向域的文件夹。例子.com
在该文件夹中/opt/bitnami/apache2/htdocs/domain
,您需要放置/error
文档和.htaccess
文件。
推荐阅读
- swiftui - 建模 JSON 货币对象
- python - 获取 SyntaxError:无效的语法,没有 pygame 的原因
- python - Celery 显示 django 的 runserver 日志而不是 celery 日志
- omnet++ - Veins 802.11p CSMA/CA 和重传
- angular - 在编辑表单时获取下拉选择的保存值
- javascript - 如果满足某些条件,则定期检查和发送电子邮件
- c++ - python中unorderd_map的替代方案是什么?我们知道 key 中的默认值:值在 c++ 中为零
- php - PHP cookie 手动删除后不再设置(谷歌浏览器)
- c# - 超过了可以同时更新的列数
- prometheus - Prometheus Alertmanager:是否可以使用动态警报名称