1

以下代码有效

AuthUserFile /etc/apache2/.htpasswd
AuthType Basic
AuthName "Please enter the username and password"
Require valid-user

以下没有

AuthUserFile /etc/apache2/.htpasswd
AuthType Basic
AuthName "Please enter the username and password"
Require valid-user
<Directory /var/www/e>
    Satisfy any
</Directory>

而不是,我的意思是它会引发服务器默认的 500 错误。

我这样做是为了尝试为 403 页面创建一个 ErrorDocument,但每当我指定一个页面时,它都会给我一个 500 错误。我最初认为这可能是因为我试图链接到的 403.html 文档受密码保护,但事实并非如此。

以下代码也会抛出 500:

AuthUserFile /etc/apache2/.htpasswd
AuthType Basic
AuthName "Please enter the username and password"
Require valid-user
ErrorDocument 403 http://google.com

相关文件读出?(我认为?)我很抱歉对此如此陌生。

root@####:~# cat /etc/apache2/sites-available/default
<VirtualHost *:80>
    ServerAdmin webmaster@localhost

        DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride none
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride AuthConfig
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride none
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@#####:~#

我只是想创建一个 403 文档,指向任何方向都会非常有帮助。我再次对这看起来多么简单表示歉意,我的 google-fu 还不够强大,无法找到与“创建 403 错误 htaccess 导致 500 错误”准确匹配的资源

4

1 回答 1

1

<Directory>指令仅允许在服务器上下文中使用(即 httpd.cont、apache2.conf、虚拟主机配置或类似的操作系统的服务器级配置文件)。

当您考虑它时,这是有道理的,因为.htaccessIS 已经在目录上下文中。

检查此链接以获取有关Directory指令的更多信息:http ://httpd.apache.org/docs/2.2/mod/core.html#directory

我猜你的ErrorDocument指令不起作用,因为你没有AllowOverride FileInfo在你的 conf 文件中设置目录。这是在指定目录中启用 ErrorDocument 和其他文件级指令所必需的。

有关更多信息,请参阅此链接AllowOverridehttp ://httpd.apache.org/docs/current/mod/core.html#allowoverride

除非您有特定的理由将指令放入 中.htaccess,否则您可能会考虑将它们放入<Directory>conf 文件中的块中,并为所有目录设置AllowOverride= none。从性能的角度来看,这更好。由于服务器不需要检查请求层次结构中的每个目录来查找.htaccess指令。

于 2014-03-21T20:24:29.703 回答