针对单个子域进行身份validation

我在Apache中有一个VirtualHost,使用ServerAlias和通配符来匹配很多子域,如下所示:

<VirtualHost> ServerName foo.com ServerAlias *.foo.com </VirtualHost> 

有几百个与别名相匹配的子域,现在我想要一个特定子域的身份validation提示: bar.foo.com

怎么会这样做呢?

我曾经想过为bar.foo.com创build一个新的VirtualHost,但是我最好避免这种情况,因为一旦我想添加更多的域名就会变得麻烦。

取决于你有什么样的目录结构(你的VirtualDocumentRoot什么样的?),但是这对于站点目录中的.htaccess文件来说可能是一个很好的情况。

 AuthType Basic AuthName "bar.foo.com" AuthUserFile /var/www/bar.foo.com/.htpasswd Require valid-user 

设置.htpasswd文件:

 htpasswd -c /var/www/bar.foo.com/.htpasswd username1 htpasswd /var/www/bar.foo.com/.htpasswd username2 ... 

如果可能的话,也encryption这个stream量。 基本身份validation通过HTTP以明文forms发送,所以最好使用SSL对其进行encryption。

我有同样的问题,现在就解决了。

假设您有两个虚拟主机“open.example.com”和“resticted.example.com”,共享文档根目录“/ path / to / your / web-root”。 你不能让人们无需密码就可以访问open.example.com,但需要inputrestricteded.example.com的密码。 那么你的configuration如下:

 <Directory /path/to/your/web-root> Order Deny,Allow Deny From All SetEnvIf Host open.example.com allowed Allow from env=allowed AuthType Basic AuthName "Won't let you in, if you don't tell me your name and password" AuthUserFile /etc/apache2/htusers Require valid-user Satisfy Any </Directory>