Page 1 of 1

Apache - Default website

PostPosted: 24. February 2014 14:59
by dave558
Hi

I'm just wondering how to set a default website in the Apache config file. I've set up the server configuration and thought that would have been the default website as below.
ServerAdmin <contact email>
ServerName <server domain>:80
UseCanonicalName Off
DocumentRoot "/var/www/html"

However, it appears that it's not the default website when entering the IP or a domain that hasn't been entered as a virtual-host entry. From trying a few different entries in the httpd.conf, it appears which ever virtual-host entry comes first becomes the default website. I've worked around this problem is by doing the following creating the entry as below.

So if I enter the server IP, mail.example.com, ftp.example.com, mail.second-example.com, etc, it'll retrieve the website from "/var/www/html" (ie the first virtual-host entry). If I entered the URL for all the website, it'll retrieve whatever documents it's meant retrieve. However, I find this somewhat not very elegant and just wondering if there's a better approach to do this.

### Section 3: Virtual Hosts
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName <the server ip>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/example.com"
ServerName example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/example.com/subdomain"
ServerName subdomain.example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/second-example.com"
ServerName second-example.com
</VirtualHost>

Re: Apache - Default website

PostPosted: 24. February 2014 22:44
by Nobbie
dave558 wrote:(ie the first virtual-host entry).


Exactly! And thats it already.

If you configure ANY VirtualHost, ALL external configurations (like Servername, DocumentRoot etc) are IGNORED. And the first VirtualHost entry is the default case, which is taken if the requested Servername does not match any other VirtualHost.

Thats all.