You can use Alias *
to catch any other trafic than thoose allowed in your virtual host, for this you have to use in the last position a virtual host with *
as alias.
Like that only defined domain will be served.
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/default
...
</VirtualHost>
<VirtualHost *:80>
ServerName another.example.com
DocumentRoot /var/www/another
...
</VirtualHost>
# /!\ THIS HAS TO BE ON THE LAST POSITION /!\
<VirtualHost *:80 *:443>
# [ Server Domain ]
ServerName localhost
ServerAlias *
# [ Cancel trafic ]
RewriteRule .* - [END,R=406]
# [ Custom Log ]
CustomLog ${APACHE_LOG_DIR}/other.log combined
</VirtualHost>
In my example only example.com
and another.example.com
will be allowed, all other domains or IP will have trafic cancelled.
To cancel the trafic you can use a redirect to -
and then add an error code, for example i used a RewriteRule to redirect to 406 Not Acceptable
(R=406
).
Here you can find the list of redirect codes:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes