Centos 7:多个虚拟主机无法正常工作

时间:2016-12-16 11:47:38

标签: apache centos virtualhost vhosts

我的服务器信息是

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 /'下有2个不同的文件夹。命名' biz'和' pin'他们尊重上述2个网站的项目文件。我试图通过以下方式配置它。

在配置

下面的/ etc / hosts中
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 / sites-available下有biz.conf和pin.conf文件。我还在/ etc / httpd下启用了文件夹站点,它有2个文件,使用以下命令指向sites-available文件夹的biz.conf和pin.conf

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有以下内容

<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网站)。但是,如果我尝试访问http://pin.example.com/,那么也会加载biz网站而不是pin网站。多个配置无法协同工作。

我还尝试将biz.conf和pin.conf的虚拟配置合并到一个文件biz.conf中,但它也没有用。

1 个答案:

答案 0 :(得分:1)

ServerName指令的语法是:

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

没有斜杠。作为副作用,由于无法识别ServerName,因此始终会提供第一个VirtualHost。