2012-01-29 107 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