如何在同一台主機上面建立多台虛擬機。換個方式說,如何在一台電腦上提供多個不同網域的網頁服務。

網路上看了很多,但是發現很多都是說半套,後來自己試了一下,也整理一下才搞清楚怎麼弄。

這邊我先自己定義幾個變數,對應後面的Code,請自行帶入取代。

$ServerName => 網域的名稱 ex www.my-test.com.tw
$FileDocument => 虛擬主機要對應到的程式位置 ex:D:/Project_Foms/develop/apache/
$FileErrorLog => 錯誤存取的紀錄檔 ex:logs/foms/www-error_log.txt
$CustomLog => 瀏覽的存取記錄 ex:logs/foms/www-access_log.txt common

NameVirtualHost $ServerName
<VirtualHost *:80>
    ServerAdmin titanexpect@hotmail.com
    DocumentRoot "$FileDocument"
    ServerName $ServerName
    ErrorLog $FileErrorLog
    CustomLog $CustomLog common
    <Directory "$FileDocument">
       Options Indexes FollowSymLinks Includes ExecCGI
       AllowOverride All
       Require all granted
       Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

把文字複製貼到apache的設定檔中,一般來說都在 \conf\httpd.conf,並依照你要的資料參考修改。
一般來說就OK了,但是如果網域名稱是你自己亂編的話。那也要麻煩你同時修改C:\Windows\System32\drivers\etc目錄下的hosts。
參考下列文字貼上。
 127.0.0.1       $ServerName
前面為IP,後面為網域名稱。這樣修改後,並把apache重新啟動。打開IE,輸入你的自訂的網域,這樣就可以看到了。

arrow
arrow
    文章標籤
    虛擬主機 apache Virtual Host
    全站熱搜

    阿基 發表在 痞客邦 留言(0) 人氣()