Apache2 virtualhosts

In order to bind a virtualhost to only one ip (if the server has several) add the ip in the VirtualHost tag, to make it listen on all ips – use *
To make the server respond to several names, use the ServerAlias and ServerAlias supports wildcards.

See the examples below for more.

<VirtualHost 111.22.33.55>
    DocumentRoot /www/subdomain
    ServerName www.sub.domain.tld
    ServerAlias *.sub.domain.tld
    ...
</VirtualHost>

<VirtualHost *>
    DocumentRoot /www/domain
    ServerName www.domain.tld
    ...
</VirtualHost>