Apache 为多个 URL 设置虚拟主机

Apache 为多个 URL 设置虚拟主机

我安装了 Bitnami Wampstack,运行 2 个不同的网站,每个网站都有两个不同的 URL。虚拟主机设置如下:

NameVirtualHost *:83
NameVirtualHost www.first.co.za:83
NameVirtualHost www.first.net:83

<VirtualHost www.first.co.za:83>
  ServerName www.first.co.za:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

<VirtualHost www.second.net:83>
  ServerName *:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

<VirtualHost www.second.co.za:83>
  ServerName www.second.co.za:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

<VirtualHost www.first.net:83>
  ServerName www.first.net:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

其中三个 URL 重定向正确,但第四个 URL www.first.co.za 显示的是 www.second.net 网站,这似乎是默认网站。我的配置有什么问题?

答案1

由于您实际上只有两个站点,我建议仅设置两个虚拟主机,并使用别名完成其余操作,如下所示:

NameVirtualHost *:83

<VirtualHost *:83>
ServerName www.first.net
ServerAlias www.first.co.za
DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

<VirtualHost *:83>
ServerName www.second.net
ServerAlias www.second.co.za
ServerAlias *
DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

这消除了冗余,使得阅读更清晰,而且更易于维护。

相关内容