htpasswd在所有子域上并通过不同的auth ip防止auth

时间:2015-02-10 16:58:41

标签: apache authentication .htpasswd

我希望所有带有* .domainname.com的子域都有一个httpasswd保护,但是2个ips允许在没有凭据的情况下进行身份验证。

<Directory /home/www/clients>
            AuthUserFile /home/www/.htpasswd
            AuthName "Acceso Privado"
            AuthType Basic
            Require valid-user
            SetEnvIf Host domainname.com secure_content
            Order Allow,Deny
            Allow from all
            Deny from env=secure_content
            Allow from XX.XX.XX.XX
            Allow from XX.XX.XX.XX
            Satisfy Any
</Directory>

但是/ home / www / clients中托管的所有域都要求我提供凭证:(

<VirtualHost *:80>
        ServerAdmin root@domainname.com
        ServerName trademark.domainname.com
        ServerAlias www.trademark.domainname.com

        DocumentRoot /home/www/clients/trademark/htdocs/

        <Directory /home/www/clients/trademark/htdocs>
                Options none FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/trademark/trademark_error.log

        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/trademark/trademark_access.log combined
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

我找到了大于或等于2.4的apache版本的解决方案

<Directory /home/www/clients>
    <If "%{REMOTE_ADDR} != 'XX.XX.XX.XX'  && %{REMOTE_ADDR} != 'XX.XX.XX.XX' && %{HTTP_HOST} -strcmatch '*.domainname.com'">
        AuthUserFile /home/www/.htpasswd
        AuthName "Acceso Privado"
        AuthType Basic
        Require valid-user
    </If>
</Directory>