Andreas
Andreas

Reputation: 728

Apache virtualhost directive: only ServerName, nothing else

If I create a vhost directive, it will always catch all requests on this IP address. Even if I set a ServerName, all other requests will be redirected to the DocumentRoot of this entry. How can I drop all requests except to this specific domain? E.g.:

VirtualHost 46.108.122.78:80
    ServerName mysite.com

(I know that I can specify a second directive without ServerName and redirect e.g. to an empty dir. However, I want to explicitly drop these requests.)

Upvotes: 0

Views: 979

Answers (1)

covener
covener

Reputation: 17872

The first name-based virtualhost for a given ip:port is the default when no other servername/serveralias matches.

# not necessary in 2.4
NameVirtualHost 46.108.122.78:80

<VirtualHost 46.108.122.78:80>
ServerName xxx.example.com
# any unmatched hostname on goes here
RewriteEngine on
RewriteRule .* - [F]
</VirtualHost>
<VirtualHost 46.108.122.78:80>
ServerName foo.example.com
DocumentRoot ...
</VirtualHost>

Upvotes: 1

Related Questions