Centos 7:多个虚拟主机不工作
Centos 7: Multiple virtual host is not working
我的服务器信息是
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 下启用了文件夹 sites-enabled,其中有 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/ , the correct website (biz website) is loading. But if i try to access http://pin.example.com/,则会加载商业网站而不是 pin 网站。多个配置不能一起工作。
我还尝试将 biz.conf 和 pin.conf 的虚拟配置合并到一个文件中,biz.conf,但效果不佳。
ServerName 指令的语法是:
ServerName [scheme://]domain-name|ip-address[:port]
没有尾部斜杠。作为副作用,由于无法识别 ServerName,因此始终会提供第一个 VirtualHost。
我的服务器信息是
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 下启用了文件夹 sites-enabled,其中有 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/ , the correct website (biz website) is loading. But if i try to access http://pin.example.com/,则会加载商业网站而不是 pin 网站。多个配置不能一起工作。
我还尝试将 biz.conf 和 pin.conf 的虚拟配置合并到一个文件中,biz.conf,但效果不佳。
ServerName 指令的语法是:
ServerName [scheme://]domain-name|ip-address[:port]
没有尾部斜杠。作为副作用,由于无法识别 ServerName,因此始终会提供第一个 VirtualHost。