正在使用aliyun主機,運行centos6.4 64位元系統,安裝lamp環境後進行網域名稱綁定。設定檔如下:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName 120.24.54.xxx
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/domain1
ServerName domain.com
ServerAlias *.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/domain2
ServerName domain.com
ServerAlias *.domain.com
</VirtualHost>
然後透過www.domain1.com
可以訪問指向/var/www/html/domain1
目錄的網站,但是透過www.domain1.com
造訪同樣是指向/var/www/html/domain1
,透過IP 120.24.54.xxx
存取也是指向domai1
目錄,設定檔其他地方都沒有動過。我想要透過IP存取就指向html
目錄,透過網域存取就指向對應的目錄。
黄舟2017-04-25 09:03:16
透過查看官方文件已經找到答案:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org
# Other directives here
</VirtualHost>
必須開啟NameVirtualHost *:80
,否則無論綁定多少個域名,全部都會指向第一個virtualhost的documentroot
怪我咯2017-04-25 09:03:16
DocumentRoot /var/www/html/domain1
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/html/domain2
ServerName domain.com
ServerAlias *.domain.com
這裡沒改掉了?