如果我在 debian 11 上安装 apache2 并访问以下其中一个 URL:
http://localhost/.htm
http://localhost/.html
我没有得到预期的 HTTP 状态代码 404,而是得到了 HTTP 状态代码 403!
但是,如果我访问 URL http://localhost/.abc,我会得到 HTTP 状态代码 404。
有人知道为什么 apache 对于不存在的文件返回 403 而不是 404./.htm
吗./.html
?
我没有更改任何配置文件,因此配置应该是 debian 11 附带的默认配置!virtualhost-config 是默认的 debian 虚拟主机配置:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
答案1
这是因为 Apache 配置默认包含以下代码片段:
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
注释很好地解释了这一点。.htaccess
和.htpasswd
是可以包含安全相关配置的文件,并且存在于 Web 根目录中。因此,默认配置只是阻止以 开头的文件.ht
。