1
  • Server: Debian 9
  • Webserver: Apache2

My DNS A Record is *.domain.tld to my IP I solve my apache vhosts by macro. If I type in a subdomain that does not exist, it will display the page of the next vhost file instead of a default page or an error.

Here is my 000-default.conf

        ServerSignature Off
<Directory /home>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

        <VirtualHost *:80>
                DocumentRoot /var/www
        </VirtualHost>



<Macro Host $name $domain>
        <VirtualHost $domain:80>
                ServerName $domain
                ServerAlias www.$domain

                DocumentRoot /home/$name/html
                AssignUserID $name $name
                CustomLog /home/$name/logs/access.log vhost_combined
                ErrorLog /home/$name/logs/error.log
                <Directory /home/$name/html>
                        php_admin_value open_basedir /home/$name/html/:/var/lib/php/:/usr/share/php/:/usr/sbin/sendmail:/tmp
                        php_admin_value upload_tmp_dir /home/$name/html/tmp/
                        php_value upload_max_filesize 500M
                        php_value post_max_size 525M
                        php_value memory_limit 2000M
                        php_flag "output_buffering" Off
                </Directory>
        </VirtualHost>
</Macro>

<Macro SSLHost $name $domain>
<IfModule mod_ssl.c>
        <VirtualHost $domain:443>
                ServerName $domain
                ServerAlias www.$domain
                Alias /analytics /home/matomo/html

                DocumentRoot /home/$name/html
                AssignUserID $name $name
                CustomLog /home/$name/logs/access.log vhost_combined
                ErrorLog /home/$name/logs/error.log
                <Directory /home/$name/html>
                        php_admin_value open_basedir /home/$name/html:/var/lib/php/:/usr/share/php/:/usr/sbin/sendmail:/tmp
                        php_admin_value upload_tmp_dir /home/$name/html/tmp
                        php_value upload_max_filesize 500M
                        php_value post_max_size 525M
                        php_value memory_limit 2000M
                        php_flag "output_buffering" Off
                </Directory>
                Include /etc/letsencrypt/options-ssl-apache.conf
                ServerAlias $domain
                SSLCertificateFile /etc/letsencrypt/live/$domain/fullchain.pem
                SSLCertificateKeyFile /etc/letsencrypt/live/$domain/privkey.pem
        </VirtualHost>
</IfModule>

and as sample a macro vhost (001-sub.domain.tld.conf:

Use Host myXYuser sub.domain.tld
Use SSLHost myXYuser sub.domain.tld

So as example now the sub.domain.tld exists When I type "xy.domain.tld" it display sub.domain.tld.. How can I avoid this?

Thanks in advance,

1 Answer 1

0

Apache 2.4 VirtualHost Examples

The asterisks match all addresses, so the main server serves no requests. Due to the fact that the virtual host with ServerName www.example.com is first in the configuration file, it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first .

Your first instance that has a ServerName directive will serve every invalid request (that specifies as ServerName).

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .