Search code examples
apachecentos7virtual-hosts

CentOS Apache VirtualHost default


I have set up some virtal host to distinguish between my subdomains (/etc/httpd/conf.d/*.conf).

This was working on my old server (Debian 7). But now if I browse the root page I get the first defined VirtualHost displayed.

Also if I am browsing an undefined subdomain I get the first VirtualHost config displayed.

<VirtualHost *:80>

    ServerAdmin admin@example.com

    ServerName sub1.example.com
    ServerAlias sub1.example.com
    DocumentRoot /home/sub/sub_sub1/www
    ServerAdmin Admin
    CustomLog /home/sub/sub_sub1/logs/access.log combined
    ErrorLog /home/sub/sub_sub1/logs/error.log
    LogLevel warn

    <Directory /home/sub/sub_sub1/www>
        Require all granted
    </Directory>

</VirtualHost>

Solution

  • The first defined VirtualHost will serve all the requests that don't get handled by the other ones. You can create a default VirtualHost that handles those requests. To make sure this VirtualHost is the first one, you should name its config-file something like "000-default.conf".

    This might also help you: VirtualHost Examples