2016-12-16 36 views
0

我的服務器信息Centos的7:多個虛擬主機不工作

Server version: Apache/2.4.6 (CentOS) 
Server built: Nov 19 2015 21:43:13 

我想配置虛擬主機2不同的網站:biz.example.com和pin.example.com被託管在同一臺服務器。 'var/www/html /'下有兩個不同的文件夾,分別命名爲'biz'和'pin',它們的受尊敬項目文件位於上述2個網站。我正試圖按照下面的方式進行配置。

在的/ etc /下面配置主機

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 
::1   localhost localhost.localdomain localhost6 localhost6.localdomain6 

xxx.xxx.xxx.xxx biz.example.com 
xxx.xxx.xxx.xxx pin.example.com 

xxx.xxx.xxx.xxx是由服務器的IP地址替換。

在/etc/httpd/conf/httpd.conf中

IncludeOptional sites-enabled/*.conf 

現在,在/ etc/httpd的/網站,提供有biz.conf和pin.conf文件。我也有文件夾的網站啓用在/ etc/httpd的其中有2個文件指向使用下面的命令

ln -s /etc/httpd/sites-available/biz.conf /etc/httpd/sites-enabled/biz.conf 

ln -s /etc/httpd/sites-available/pin.conf /etc/httpd/sites-enabled/pin.conf 

biz.conf具有以下站點可用的文件夾的biz.conf和pin.conf

<VirtualHost *:80> 
ServerName http://biz.example.com/ 
ServerAlias http://biz.example.com/ 
DocumentRoot "/var/www/html/biz" 
<directory "/var/www/html/biz"> 
     Options Indexes FollowSymLinks 
     AllowOverride all 
     Order Deny,Allow 
     Allow from 127.0.0.1 
</directory> 
</VirtualHost> 

而且pin.conf文件中的配置被提及作爲

<VirtualHost *:80> 
ServerName http://pin.example.com/ 
ServerAlias http://pin.example.com/ 
DocumentRoot "/var/www/html/pin" 
<directory "/var/www/html/pin"> 
     Options Indexes FollowSymLinks 
     AllowOverride all 
     Order Deny,Allow 
     Allow from 127.0.0.1 
</directory> 
</VirtualHost> 

在此設置,如果我嘗試訪問http://biz.example.com/,正確的網站(BIZ網站)是LO ading。但如果我嘗試訪問http://pin.example.com/,那麼也biz網站正在加載而不是pin網站。多個配置不能一起工作。

我也嘗試將biz.conf和pin.conf的虛擬配置合併到一個單獨的文件biz.conf中,但它沒有工作。

+0

'/ etc/httpd/sites-enabled /'中是否還有其他'.conf'文件?有沒有在'/ etc/httpd/conf/httpd.conf'中定義的VirtualHosts? –

+0

@DusanBajic:對於這兩個問題都沒有。 – Debashis

+1

嘗試從[ServerName]和[ServerAlias]中刪除尾部斜線(事實上,因爲它與ServerName相同,所以您根本不需要ServerAlias) –

回答

1

ServerName指令的語​​法是:

ServerName [scheme://]domain-name|ip-address[:port] 

沒有結尾的斜線。作爲副作用,由於無法識別ServerName,因此始終提供第一個VirtualHost。