Reputation: 19687
In Apache web server, when using name-based virtual hosting you can use either the IP or the actual domain name in the VirtualHost
directive.
(Name-based virtual hosting on Debian is enabled via /etc/apache/ports.conf
through NameVirtualHost <ip>:<port>
statement, where <port>
has to be the same one as in a Listen
directive.)
So, then this:
<VirtualHost 10.0.0.1:80>
...
or this:
<VirtualHost sub.domain.tld:80>
...
will equally work.
What are the differences, and which approach should be preferred?
Upvotes: 2
Views: 610
Reputation: 21306
Using an IP address is preferred so that your config can be parsed even if DNS resolution fails.
You can use the ServerName directive to control which hostname the VirtualHost block applies to, without triggering a DNS resolution:
<VirtualHost 10.0.0.1:80>
ServerName sub.domain.tld
...
</VirtualHost>
http://httpd.apache.org/docs/current/dns-caveats.html has more examples of good and bad practice.
Upvotes: 2