我在www.domain.com上有主網站,並創建了一個名爲demo.domain.com的子域名爲 ,但是當我嘗試訪問子域名demo.domain.com時,它顯示與我的主域相同的網站,我該如何解決這個問題? 下面是我如何在我的Apache 2.2子域名顯示與主域名相同的網站
/etc/httpd/conf/httpd.conf中
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/domain.com/public_html
ServerName domain.com
ServerAlias www.domain.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/demo.domain.com/public_html
ServerName demo.domain.com
ServerAlias www.demo.domain.com
</VirtualHost>
我甚至試過
service httpd restart
它拋出
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Mon Jan 13 15:54:14 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
定義的虛擬主機
我在主文件中添加了主域和子域
[[email protected]_html]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 domain.com demo.domain.com
我在我的DNS管理器中爲子域名創建了一個A記錄,指向我的主vps IP地址。 我的DNS文件
demo IN A 1.2.3.4
@ IN A 1.2.3.4
www IN A 1.2.3.4
所以,當我訪問domain.com和demo.domain.com它顯示
我已經在
創建的index.html在同一個頁面domain.com的/var/www/demo.domain.com/public_html
[[email protected]_html]# cat index.html
<html>
<head>
<title>www.example.com</title>
</head>
<body>
<h1>Success: You Have Set Up a Virtual Host</h1>
</body>
</html>
所以我是如何解決這一問題?我使用CentOS 6的,64位
當我嘗試訪問的子域demo.domain.com,其顯示的同一站點中我的主域名www.domain.com
你在你的httpd.conf中有'NameVirtualHost *:80'的地方嗎?沒有這個,你將會打到默認的VirtualHost。 – arco444
是的,我有#NameVirtualHost *:80 在我的httpd.conf中,但它的註釋掉了。 – AMB
我剛剛評論它,並重新啓動apache和瞧,它的作品.... +1 – AMB