... Port 80 ServerName server.domain.tld NameVirtualHost 22.214.171.124 DocumentRoot /www/domain ServerName www.domain.tld ... DocumentRoot /www/subdomain ServerName www.sub.domain.tld ...
Apart from localhost there are no unspecified addresses/ports, therefore the main server only serves localhost requests. Due to the fact that www.domain.tld has the highest priority it can be seen as the default or primary server.
- Setup 2: The server machine has two IP addresses (126.96.36.199 and 188.8.131.52) which resolve to the names server1.domain.tld and server2.domain.tld respectively. The alias www.domain.tld should be used for the main server which should also catch any unspecified addresses. We want to use a virtual host for the alias www.otherdomain.tld and another virtual host, with server name www.sub.domain.tld, should catch any request to hostnames of the form *.sub.domain.tld. The address 184.108.40.206 should be used for the virtual hosts.
... Port 80 ServerName www.domain.tld DocumentRoot /www/domain NameVirtualHost 220.127.116.11 DocumentRoot /www/otherdomain ServerName www.otherdomain.tld ... DocumentRoot /www/subdomain ServerName www.sub.domain.tld ServerAlias *.sub.domain.tld ...
Any request to an address other than 18.104.22.168 will be served from the main server. A request to 22.214.171.124 with an unknown or no
Host:header will be served from www.otherdomain.tld.
- Setup 3: The server machine has two IP addresses (192.168.1.1 and 126.96.36.199). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the name server1.domain.tld resolves to the external address (188.8.131.52), but inside the network, that same name resolves to the internal address (192.168.1.1).
The server can be made to respond to internal and external requests with the same content, with just one
... NameVirtualHost 192.168.1.1 NameVirtualHost 184.108.40.206 DocumentRoot /www/server1 ServerName server1.domain.tld ServerAlias server1 ...
Now requests from both networks will be served from the same
- Setup 4: You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in the “NameVirtualHost” tag, you can allow this to work. If you try using without the NameVirtualHost name:port or you try to use the Port directive, your configuration will not work.
... NameVirtualHost 220.127.116.11:80 NameVirtualHost 18.104.22.168:8080 ServerName www.domain.tld DocumentRoot /www/domain-80 ServerName www.domain.tld DocumentRoot /www/domain-8080 ServerName www.otherdomain.tld DocumentRoot /www/otherdomain-80 ServerName www.otherdomain.tld DocumentRoot /www/otherdomain-8080