third level domain and debian

I have a very basic knowledge of how a web server works. I wish to learn how to set a third level domains test1.mysite.tld such that it points to a web server subdirectory /var/www/test1/. (www.mysite.tld should keep to point to main directory). I am on a machine with Debian. I defined a virtual host within apache2.conf

<VirtualHost *>
ServerName test1.mysite.tld
DocumentRoot /var/www/test1/
LogLevel debug
ErrorLog other_vhosts_access.log
</VirtualHost>

Still, when I try url test1.mysite.tld, /var/www/index.html is returned, instead of /var/www/test1/index.html.

Do I miss something? A rewrite rule? Do I need to do anything for the DNS? Thanks for your help


You need to configure name based virtual hosting. The first thing to do is configure the DNS so that test1.mysite.tld resolves to the IP address of your server. How you do this depends upon how your DNS services are provided.

Basic Apache configuration would be something like

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>

    ServerName www.mysite.tld 
    Serveralias mysite.tld
    DocumentRoot /var/www/mysite.tld
    ...
</VirtualHost>

<VirtualHost *:80>
    ServerName test1.mysite.tld
    DocumentRoot /var/www/test1/
    LogLevel debug
    ErrorLog other_vhosts_access.log
</VirtualHost>