我有两个域,这是我的配置文件:
<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>
我不明白的是:
main-site.example
和www.main-site.example
是可访问的,并指向main-site.example
,所以没关系www.second-site.example
仅指main-site.example
我second-site.example
它有效且我不明白为什么答案 0 :(得分:0)
添加ServerAlias
指令以定义您的虚拟主机。否则,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>