Primary Default Website in Virtualmin (Apache)

When no virtual websites are in existence, The Apache web server will point to /var/www/html and /var/www/cgi-bin in a base install of Virtualmin (the default). However when a Virtual website is created, this changes to the first available virtual site, so for example, if the hostname is some.domain.com and no virtual sites are configured, typing this URL in a browser will serve the content in /var/www/html. If a virtual site called virtualsite.com is created, the same request will serve the content of /home/virtualsite/public_html.

By design this is normal

Whilst this is the way Apache is designed and there’s nothing wrong with that, it becomes a problem when some applications are only available outside the virtual server realm (i.e. not suexec’ed). For example the server has Nagios or Munin installed and you want to be able to access it even after a virtual server has been created. The solution is to manually create the first virtual server and call it the same as the server hostname (some.domain.com).

Example of a manually edited httpd.conf

Below is an example of the content of my current config file, the domain have been renamed to protect the innocents. Note that this must be the first Virtual Server. (to make things easier, I first created a virtual server and used it as a template, this server was then deleted)

#### DEFAULT virtual server - edited by Gilbert
#### Port 80
<VirtualHost 001.008.003.126:80>
ServerName some.domain.com
DocumentRoot /var/www/html
ErrorLog /var/log/error_log
CustomLog /var/log/access_log combined
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /var/www/html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /var/www/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
</VirtualHost>
#### End port 80
#### Port 443 (SSL)
<VirtualHost 001.008.003.126:443>
ServerName some.domain.com
DocumentRoot /var/www/html
ErrorLog /var/log/error_log
CustomLog /var/log/access_log combined
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /var/www/html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /var/www/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
SSLEngine on
SSLCertificateFile /etc/webmin/domain.com.cert
SSLCertificateKeyFile /etc/webmin/domain.com.key
</VirtualHost>

Note that the above is for port 80 and 443 (SSL), the path to the SSL certificate file and key is my customisation, the files must be copied to the right place.

When a domain’s A record points to this server but there’s no matching virtual site, the default will return a 404. To avoid this, simply set the “Automatic Virtual Host” of the “Default Server” (Server > Apache Webserver > Existing Virtual Hosts [Tab] > Default Server > Automatic Virtual Hosts to: /var/www/html.

The above  makes ALL Virtual sites point to the default path, so avoid.

This is one of many ways to do it. It just worked as required for my own needs.

It is also to be noted that this virtual site is not showing in the list of “virtual  Servers” in the Virtualmin Control Panel which is I think a rather good idea as I will not be able to have it deleted by accident!

One thought on “Primary Default Website in Virtualmin (Apache)”

Comments are closed.