Wednesday, November 17, 2021

[SOLVED] Multiple Aliases for Multiple vhosts httpd

Issue

I want any domain to point a CNAME on my vhosts for that i use

ServerAlias *

in my vhosts but it only works with one vhost if I add it in both the CNAME pointed to the second vhost serves the contented from the first vhost.

e.g:
1st: files.domain.com CNAME to files.example.com
2nd: r.domain.com CNAME to r.example.com

but second one is also serving files.example.com

My httpd.conf has these two vhosts

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/files.example.com
    ServerName files.example.com
    ErrorLog /var/www/files.example.com/logs/error_log
    CustomLog /var/www/files.example.com/logs/custom_log common
    <Directory "/var/www/files.example.com">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/r.example.com
    ServerName r.example.com
    ErrorLog /var/www/r.example.com/logs/error_log
    CustomLog /var/www/r.example.com/logs/custom_log common
    <Directory "/var/www/r.example.com">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Solution

You have to add ServerAlias lines

below ServerName files.example.com add ServerAlias files.domain.com

and below ServerName r.example.com add ServerAlias r.domain.com

In your case apache uses files.example.com as default vhost, because it is first one.



Answered By - Tero Korpela