2012-01-29 77 views
2

我想设置一个虚拟主机,它可以根据用于访问它的主机名动态处理所有请求。如果%{HTTP_HOST}可以在DocumentRoot的使用,这可能是我想要的东西:设置动态虚拟主机(Ubuntu上的Apache2)

<VirtualHost *:80> 
    ServerAdmin [email protected] 

    DocumentRoot /var/www/live/%{HTTP_HOST}/public 
    <Directory /> 
      Options FollowSymLinks 
      AllowOverride None 
    </Directory> 
    <Directory /var/www/live/%{HTTP_HOST}/public> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride None 
      Order allow,deny 
      allow from all 
    </Directory> 

    # Possible values include: debug, info, notice, warn, error, crit, alert, emerg. 
    LogLevel warn 
    ErrorLog /var/www/live/%{HTTP_HOST}/logs/error.log 
    CustomLog /var/www/live/%{HTTP_HOST}/logs/access.log combined 
</VirtualHost> 

...不幸的是,%{HTTP_HOST}不DocumentRoot文件(Warning: DocumentRoot [/var/www/live/%{HTTP_HOST}/public] does not exist)允许的。我还能如何实现我的目标?

更新:我想指出一个包罗万象的虚拟主机到一个单一的目录和具有的.htaccess使用mod_rewrite动态地选择路径,但(诚实),累死我了。我会在早上再试一次,但同时,如果任何人有好的想法,我很乐意听到他们!谢谢!

+2

http://httpd.apache.org/docs /2.0/vhosts/mass.html 我想读这个链接。愿它帮助你。 – 2012-01-29 07:09:43

+0

@HemangRami,如果你想把它写成答案,我会接受它:) – 2012-01-30 02:11:15

回答

3

也许你可以试试这个解决方案:"Apache: Dynamic Virtual Hosts"

+0

这真的很直接 – d0x 2013-11-07 16:39:28

+0

是的,这是一个很好的直接方法,但是要注意使用'VirtualDocumentRoot'实际会影响'mod_rewrite'规则(在WordPress,Drupal和许多PHP框架中使用)。它要求您为每个应用程序应用一个“RewriteBase”规则。我仍然试图找出解决方法。 – 2016-06-27 23:54:12