简体   繁体   English

Apache2和两个网站的配置文件

[英]Configuration file for Apache2 and two websites

I have two domains and this is my configuration file: 我有两个域,这是我的配置文件:

<VirtualHost *:80>
 ServerAdmin hello@example.com
 DocumentRoot /var/www/html/
 ServerName main-site.example
</VirtualHost>
<VirtualHost *:80>
 ServerAdmin hello@example.com
 DocumentRoot /var/www/example.com/public_html/
 ServerName second-site.example
</VirtualHost>

What I do not understand is this: 我不明白的是:

  • main-site.example and www.main-site.example are accesible and point at main-site.example , so this is ok main-site.examplemain-site.example www.main-site.example并指向main-site.example ,所以可以
  • but www.second-site.example points to main-site.example only if I do second-site.example it works and I do not understand why 但是www.second-site.example指向main-site.example仅在我执行second-site.example时有效,并且我不理解为什么

Add the ServerAlias directive to define your virtualHosts. 添加ServerAlias指令以定义您的virtualHosts。 Otherwise Apache will match www.second-site.example with the first *:80 VirtualHost . 否则,Apache将www.second-site.example与第一个*:80 VirtualHost匹配。

<VirtualHost *:80>
  ServerName main-site.example
  ServerAlias www.main-site.example
  ServerAdmin hello@example.com
  DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
 ServerName second-site.example
 ServerAlias www.second-site.example 
 ServerAdmin hello@example.com
 DocumentRoot /var/www/example.com/public_html/
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM