虽然我知道这个主题已经在其他一些线程中进行了讨论,但在这些线程中将解释如何在Apache中配置Virtualhost。问题是在寻找可能的答案后,我的问题在这里,研究谷歌和阅读Apache的官方文件,我无法解决我的问题。
首先,我在Apache2.4上安装了一个WordPress安装,安装在CentOS 7中,并设置了以下Virtualhost:
<VirtualHost *:80>
ServerName subdomain1.domain.com
ServerAlias www.subdomain1.domain.com
DocumentRoot /some/path/to/wordpress
<Directory "/some/path/to/wordpress">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/subdomain1-error.log"
CustomLog "logs/subdomain1-access.log" combined
LogLevel warn
</VirtualHost>它运行良好,但后来我决定添加Moodle安装(因为服务器没有太多的流量),然后如果我浏览Chrome subdomain1.domain.com或subdomain2.domain.com并不重要,Chrome总是去subdomain2.domain.com (Moodle网站)。
我在Chrome和Firefox中尝试了同样的结果。moodle Virtualhost是:
<VirtualHost *:80>
ServerName subdomain2.domain.com
ServerAlias www.subdomain2.domain.com
DocumentRoot /some/path/to/moodle
<Directory "/some/path/to/moodle">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/subdomain2-error.log"
CustomLog "logs/subdomain2-access.log" combined
LogLevel warn
</VirtualHost>另外,Apache配置文件httpd.conf使用以下指令包含这些VirtualHosts : IncludeOptional con.d/*..conf
文件/etc/hosts是:
127.0.0.1 localhost
134.122.191.221 subdomain1.domain.com
134.122.191.221 subdomain2.domain.com我在Apache配置文件中看不到任何明显的错误,所以如果有人能给我一个提示,说明它的错误和任何可能的错误,我将不胜感激。
非常感谢。
发布于 2016-02-17 10:56:37
您正在尝试设置基于名称的虚拟主机,但缺少一个重要的配置:
NameVirtualHost *:80因此,在httpd.conf中添加上面的行并重新启动apache/httpd,就可以解决这个问题。
注:根据Apache2.4文档的说法,这个指令被废弃了,不再需要了。
在2.3.11之前,
NameVirtualHost必须指示服务器特定的IP地址和端口组合可以作为基于名称的虚拟主机使用。在2.3.11及更高版本中,在多个虚拟主机中使用IP地址和端口组合时,该地址将自动启用基于名称的虚拟主机。
但是我还没有弄清楚为什么它适用于上面的指令。
https://serverfault.com/questions/757779
复制相似问题