2014-01-07 29 views
3

我麻煩設置虛擬主機後更新Ubuntu 13.10! 這是我的嘗試:如何爲Apache 2.4/Ubuntu 13.10及以上版本設置虛擬主機?

火起來的終端類型:

sudo a2enmod vhost_alias 

如果你沒有得到任何錯誤信息和你的回報看起來像下面,你是在正確的軌道上。

Enabling module vhost_alias. 
Run '/etc/init.d/apache2 restart' to activate new configuration! 

接下來要做的是通過鍵入

cd /etc/apache2/sites-available/ 

OK轉到網站可用的目錄,現在我們是在阿帕奇目錄中的所有虛擬主機的定義文件。我們要複製默認的模板之一,cryptically命名默認

sudo cp default our-test-site 

這將創建一個默認模板的副本命名我們的測試現場(你當然應該有任何你希望它替換)。讓我們來編輯它,類型

sudo gedit our-test-site 

這將在編輯器中打開文件,下面是默認的虛擬主機文件的內容(像往常一樣因人而異,如果你做了一些定製)

ServerAdmin [email protected] 

DocumentRoot /var/www 

     Options FollowSymLinks 
     AllowOverride None 


     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 


    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 

     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 


    ErrorLog /var/log/apache2/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog /var/log/apache2/access.log combined 

    Alias /doc/ "/usr/share/doc/" 

     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 

我們需要添加一行並編輯兩行。

在DocumentRoot指令的正上方(第4行的前面)添加ServerName our-test-site.local。

在第4行上編輯DocumentRoot/var/www路徑並將其設置爲/路徑到測試站點-withOUT-trailing-slash。它應該是這個樣子

DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash 

如果你沒有注意到我的微妙的暗示,不應該有在路徑的最後一個斜線。

編輯第9行的路徑,並將其設置爲/路徑到測試站點-with-trailing-slash /。它應該是這個樣子

DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash 

如果你沒有注意到我的微妙的暗示,應該是在路徑的結尾斜線。

在那裏,你有它,幾乎完成,虛擬主機文件被設置。通過鍵入

sudo a2ensite our-test-site 

響應允許它應該是這樣的

Enabling site our-test-site. 
Run '/etc/init.d/apache2 reload' to activate new configuration! 

此時虛擬主機設置完成後,所有剩下的就是告訴服務器,我們的測試部位。本地應該被重新設置爲127.0.0.1。我們通過輸入

sudo gedit /etc/hosts 

並在localhost(第1行)後添加127.0.0.1 our-test-site.local。

整個hosts文件應該像

127.0.0.1 localhost 
127.0.0.1 our-test-site.local 
127.0.1.1 ubuntu-vm 

# The following lines are desirable for IPv6 capable hosts 
::1  localhost ip6-localhost ip6-loopback 
fe00::0 ip6-localnet 
ff00::0 ip6-mcastprefix 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 
ff02::3 ip6-allhosts 

保存它,關閉編輯器,最後鍵入

sudo /etc/init.d/apache2 restart 

sudo apache2ctl restart 

所以你去,你的虛擬主機安裝後,打開瀏覽器並輸入http://our-test-site.local並享受。

更新:如果您在訪問本地主機的內容時遇到問題,應該將ServerName localhost添加到默認虛擬主機(如上面針對新虛擬主機所述)。然後禁用和啓用的網站,並重新啓動Apache

sudo a2dissite default 
sudo a2ensite default 
sudo /etc/init.d/apache2 restart 

更新2:在您的新的虛擬主機文件,你應該改變你

AllowOverride None 

AllowOverride All 

你的前兩個目錄節點(/ one和具有到您站點的路徑的節點)。這將允許所有.htaccess文件正常工作並允許重定向。

當然不要忘了

sudo a2dissite our-test-site 
sudo a2ensite our-test-site 
sudo /etc/init.d/apache2 restart 

回答

6

的問題是,與Apache 2.4/Ubuntu的13.10和上方的部位,可用文件都喜歡的name.conf代替

​​

我做到了像這樣

sudo cp default.conf our-test-site.conf 

依此類推。

+2

我使用的Ubuntu 12.04和更新Apache後我也不得不改變文件名 –