xampp – 建立虛擬主機路徑

若打算將網址 mylib.com.tw 對應到本機伺服器 http://localhost/test 的方法。

 

設定 hosts

打開 C:\Windows\System32\drivers\etc\hosts 編輯,可以在最底下添加指向後存檔

127.0.0.1 mylib.com.tw

 

設定 httpd.conf

打開 C:\xampp\apache\conf\httpd.conf 後發現裡面有這行,代表 xampp 把虛擬主機的設定檔而外引入。這麼做的好處是避免整份 httpd.conf 太過凌亂。

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

所以我們打開 C:\xampp\apache\conf\extra\httpd-vhosts.conf 添加這段文字,並將 DocumentRoot、 ServerName、Directory 修改對應後存檔。

<VirtualHost mylib.com.tw:80>
    DocumentRoot "C:\xampp\htdocs\www\test"
    ServerName mylib.com.tw
    <Directory "C:\xampp\htdocs\www\test">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

建議重新啟動 apache 後,網址打上 http://mylib.com.tw/ 就可以看到了。

參考網址

 

Comments

發表迴響