通过htpasswd进行子域基本身份验证时出错

时间:2014-06-17 13:24:14

标签: laravel apache2 .htpasswd

问题:

我让Laravel在Apache 2.4.9上运行,我的域名组织如下:

beta.domain.com    => /var/www/beta
www.domain.com     => /var/www/live

beta子域具有基本身份验证。除非我开始探索apache2错误日志,否则一切都按预期工作。我收到以下错误消息:

  

AH01797:服务器配置拒绝客户端:   /var/www/beta/public/index.php,referer:https://beta.domain.com/

我的设置:

这是我的设置:

<VirtualHost *:80>

    # Redirect all http traffic to https

    Redirect 301 / https://www.domain.com/

</VirtualHost>

<VirtualHost *:443>

    # some SSL setup for www here

    ServerName www.domain.com

    DocumentRoot /var/www/live/public
    <Directory /var/www/live/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>


    LogLevel warn

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

    SetEnv ENVIRONMENT "live"

</VirtualHost>

<VirtualHost *:443>

    # some SSL setup for beta here

    ServerName beta.domain.com

    DocumentRoot /var/www/beta/public
    <Directory /var/www/beta/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny

        # allow from one ip
        Allow from xxx.xxx.xxx
        Satisfy any

        AuthUserFile /path/to/htpasswd/.htpasswd
        AuthName "Password required"
        AuthType Basic
        Require valid-user

    </Directory>


    LogLevel warn

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

    SetEnv ENVIRONMENT "beta"

</VirtualHost>

尝试失败:

我找到了几个不同的答案,但没有一个对我有用。这些似乎是最有说服力的,但它们再次对我没用。

  1. <Directory>标签(http://httpd.apache.org/docs/current/mod/mod_auth_basic.html#authbasicprovider)替换<Location> - 错误消失了,但我丢失了基本身份验证

  2. 使用Require all granted代替Order allow/deny - 这也是     删除了我的基本身份验证。也不确定这是否成功     在我的场景中有意义。

1 个答案:

答案 0 :(得分:0)

因为我使用的是Apache 2.4+,所以我改变了

Order allow, deny
Allow from all

简单地

Require all granted

这会修复错误消息,但为了允许在beta子域上进行基本身份验证,我还必须删除Satisfy any

因此,测试版的设置将更改为:

<Directory /var/www/beta/public>

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    # removed in 2.4
    # Order allow,deny

    # allow from one ip
    Require ip xxx.xxx.xxx
    # No longer require Satisfy any in 2.4
    # Satisfy any

    AuthUserFile /path/to/htpasswd/.htpasswd
    AuthName "Password required"
    AuthType Basic
    Require valid-user

</Directory>