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 www.second-site.example
points to main-site.example
only if I do second-site.example
it works and I do not understand why Add the ServerAlias
directive to define your virtualHosts. Otherwise Apache will match www.second-site.example
with the first *: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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.