Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache default VirtualHost

How can I set a default VirtualHost in Apache?

Preferably, I want the default host not to be the same as the IP address host. Now I have something like this:

NameVirtualHost *  <VirtualHost *>     ServerAdmin [email protected]     DocumentRoot /someOtherDir/     ServerAlias ip.of.the.server </VirtualHost>  <VirtualHost *>     ServerAdmin [email protected]     DocumentRoot /someroot/     ServerAlias domain.com *.domain.com </VirtualHost *> 

If a domain is forwarded to my server, but isn't in this vhost.conf file, the files from /someOtherDir/ are loaded, as expected. But I want to be able to use a different root for the IP address itself and domains which aren't added to the vhost.conf file (yet). Is this possible?

like image 328
Tiddo Avatar asked Mar 25 '11 00:03

Tiddo


People also ask

What is Virtualhost in Apache server?

The Apache HTTP server supports virtual hosts, meaning that it can respond to requests that are directed to multiple IP addresses or host names that correspond to the same host machine. You can configure each virtual host to provide different content and to behave differently.

What is default virtual host?

A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file).

How do you find the default virtual host?

The solution is easy, because we can simply add the new IP address ( 172.20. 30.50 ) to the VirtualHost directive. The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as a name-based vhost).

What is Virtualhost _default _: 443?

<Virtualhost 10.0. 0.2:*> means "I'll use this virtualhost for request coming on my 10.0. 0.2 interface" <Virtualhost _default_:443> means "I'll use this virtualhost for all other network interface on my host for request coming on port 443"


1 Answers

I found the answer: I remembered that Apache uses the first block if no other matching block is found, so I've added a block without a serveralias at the top of the blocks:

NameVirtualHost *  <VirtualHost *>     DocumentRoot /defaultdir/ </VirtualHost>  <VirtualHost *>     ServerAdmin [email protected]     DocumentRoot /someOtherDir/     ServerAlias ip.of.the.server </VirtualHost>  <VirtualHost *>     ServerAdmin [email protected]     DocumentRoot /someroot/     ServerAlias domain.com *.domain.com </VirtualHost> 
like image 183
Tiddo Avatar answered Oct 18 '22 05:10

Tiddo