首要條件就是dns要設定正解至虛擬主機IP
test.com dns設定
dns IN A 123.123.123.123
w1 IN CNAME dns
w2 IN CNAME dns
在/etc//apache2/sites-available/ 建立 test.com 檔並編輯
<VirtualHost *:80>
DocumentRoot /var/www
ServerName 192.168.1.6
ServerAdmin w1@test.com
ErrorLog logs/w1.test.com-error_log
CustomLog logs/w1.test.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/w1
ServerName w1.test.com
ServerAdmin w1@test.com
ErrorLog logs/w1.test.com-error_log
CustomLog logs/w1.test.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/w2
ServerName w2.test.com
ServerAdmin w2@test.com
ErrorLog logs/w2.test.com-error_log
CustomLog logs/w2.test.com-access_log common
</VirtualHost>
存檔後,執行a2ensite
root@public:/etc/apache2/sites-available# a2ensite
Your choices are: default default-ssl test.com
Which site(s) do you want to enable (wildcards ok)?
輸入test.com
接著重新啟重apache
在網址列輸入w1.test.com 與 w2.test.com就會各別連至不同的網站了.
沒有留言:
張貼留言