【发布时间】:2017-05-02 05:02:29
【问题描述】:
我的服务器信息是
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 个文件使用以下命令指向站点可用文件夹的 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/ ,则正在加载正确的网站(商务网站)。但是,如果我尝试访问 http://pin.example.com/ ,那么 biz 网站也在加载而不是 pin 网站。多个配置不能一起工作。
我还尝试将 biz.conf 和 pin.conf 的虚拟配置合并到一个文件 biz.conf 中,但效果不佳。
【问题讨论】:
-
/etc/httpd/sites-enabled/中还有其他的.conf文件吗?/etc/httpd/conf/httpd.conf中是否定义了任何 VirtualHosts? -
@DusanBajic:两个问题都没有。
-
尝试删除
ServerName和ServerAlias中的尾部斜杠(实际上您根本不需要ServerAlias,因为它与ServerName 相同) -
哇...它在尾部斜杠和删除 ServerAlias 后工作。谢谢@DusanBajic
标签: apache centos virtualhost vhosts