密码保护虚拟文件根目录

我有以下设置,用于自动生成在/etc/apache2/apache2.conf(在Debian 7.0上运行)中configuration的子域/虚拟文档根目录。

<VirtualHost *:80> ServerAlias * UseCanonicalName Off VirtualDocumentRoot /home/%2/htdocs/%1 # Setup correct (virtual) document root as $_SERVER['DOCUMENT_ROOT'] for PHP php_admin_value auto_prepend_file /home/jbraun/setdocroot.php <Directory /home/%2/htdocs/%1> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html index.php # These lines don't work AuthType Basic AuthName "HALMA" AuthUserFile /usr/local/apache/passwd/passwords Require valid-user # Commented for testing purposes only # Allow from halma.lan # Satisfy any </Directory> CustomLog ${APACHE_LOG_DIR}/vhost_access.log combined 

什么是工作,什么是关于

以上configuration允许用户在/home/username/htdocs/目录下创build子目录,并通过dynamic生成的子域在浏览器中访问它们,例如,可以通过http://project.jbraun.halma.lan访问/home/jbraun/htdocs/project文件夹http://project.jbraun.halma.lan (其中halma.lan是本地Intranet名称,相应的DNS设置和工作)。 此外,整个故事可以通过DynDNS服务在类似的URL从外部的project.jbraun.foobar.dyndns.org访问。

我想要达到什么目的,而且不能工作

我想从本地networking( halma.lan或者说192.168.2.* )进行访问,而不需要密码保护,而通过DynDNS URL( project.jbraun.foobar.dyndns.org )访问广域网的访问应该由密码保护。

因此,我遵循Apache文档并添加了“Auth *”行

  AuthType Basic AuthName "HALMA" AuthUserFile /usr/local/apache/passwd/passwords Require valid-user 

但不幸的是没有任何反应(是的,我在此期间重新启动了Apache)。 服务器的错误日志文件也是沉默的。

当我在我的一些项目中添加相同的行.htaccess文件一切正常,因此我认为在configuration中必须存在VirtualDocumentRoot和/或dynamic生成的文件path的问题。

有人可以指点我正确的方向,我怎么能做到这一点,或者如果有可能呢?

非常感谢。

* [编辑] *

我想发布最后工作的configuration,仅供参考和search此问题的其他人员使用:

  <VirtualHost *:80> ServerAlias *.*.halma.lan ServerAlias *.*.foobar.dyndns.org UseCanonicalName Off VirtualDocumentRoot /home/%2/htdocs/%1 # Setup correct (virtual) document root as $_SERVER['DOCUMENT_ROOT'] for PHP php_admin_value auto_prepend_file /home/jbraun/setdocroot.php #<Directory /home/%2/htdocs/%1> <Directory ~ "^/home/.*/htdocs/.*/"> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny DirectoryIndex index.html index.php AuthType Basic AuthName "HALMA" AuthUserFile /usr/local/apache/passwd/passwords Require valid-user Allow from 10.0.0 Satisfy Any </Directory> CustomLog ${APACHE_LOG_DIR}/vhost_access.log combined </VirtualHost> 

感谢HBruijn

我认为可以说%1%2扩展只发生在less数支持这种魔法的mod_vhost_alias指令中。

这可能是一个例子,其中安全性稍差的Location指令可以用来包含authentication指令

 <Location /> AuthType Basic AuthName "HALMA" AuthUserFile /usr/local/apache/passwd/passwords Require valid-user </Location> 

或者,一个Directory指令也可能包含正则expression式,允许类似于:

 <Directory ~ "^/home/.*/htdocs/.*/"> </Directory> 

你可以通过添加一个匹配你的用户名命名约定的正则expression式来改善,比如"^/home/([a-z_][a-z0-9_]{0,30})/htdocs/.*/"