Default website with mass hosting enabled


Hi all, I have a vanilla Symbiosis setup which works great.

The only thing I want is to be able to set a default site which should be served if no specific site is present for the hostname requested.

Pointing random hostnames at the machine IP currently gives a 404 rather than serving /var/www/html (which would be acceptable) or any of my /srv/ sites (which would be fine too if I could pick a default).

Thanks for any help you can offer.


Hi @cwnbigv01

I would suggest either placing a default index page into /srv/your.hostname.ext/public/htdocs/ tailored to how you wish it to look or

Place the following into a index.php in the same location;


//  Permanent redirect 301
header("HTTP/1.1 301 Moved Permanently");

//  Redirect to chosen domain

return exit;





You would need to create a catch all Apache VHosts file thats pointed to a directory with your pages.



I noticed Symbiosis has /etc/apache2/sites-available/000-default.conf, which has <VirtualHost *:80> and serves /var/www/html.

I created the required symlink in /etc/apache2/sites-enabled for this conf to be enabled and restarted apache, but if I point a random hostname to the machine I still see a 404, and the 404 is logged in zz-mass-hosting.access.log instead of access.log as 000-default.conf would suggest.

I think this part of zz-mass-hosting.conf is catching everything not explicitly defined in another vhost and resulting in a 404 for unknown hostnames:

    <IfModule vhost_bytemark_module>
            # We need a wildcard server alias, so Apache knows to check
            # where when names don't match elsewhere.
            ServerAlias *

            #  The document root + CGI-directories.
            VirtualDocumentRoot     /srv/%0/public/htdocs/
            <IfModule cgi_module>
                    VirtualScriptAlias      /srv/%0/public/cgi-bin/

This agrees with the documentation at in section 3.1: “If this directory does not exist, a 404 Not Found error will be returned.”

I just want to change the behaviour so that if the directory doesn’t exist, a default site gets served instead.

@hostsharp, thanks for the suggestion but in my use-case the machine doesn’t know in advance all hostnames pointing to it.


Back up zz-mass-hosting.conf,

then change

VirtualDocumentRoot /srv/%0/public/htdocs/
DocumentRoot /srv/DEFAULT.SITE.DOMAIN/public/htdocs/

Restart Apache. (sudo service apache2 restart)

That SHOULD get you what you want.


@taptapgroup Wow – that works perfectly, thanks! The only thing is, I have no idea how the other vhosts are still working without VirtualDocumentRoot, but they are.

Any unknown hosts now serve the machine’s default site as desired.

Before I saw your post I’d had a breakthrough with leaving VirtualDocumentRoot but adding

Alias /fallback /srv/DEFAULT.SITE.DOMAIN/public/htdocs/
ErrorDocument 404 /fallback/index.php

And then have index.php be

$hostname = $_SERVER['HTTP_HOST'];
if (substr($hostname, 0, 4) === "www.")
        $hostname = substr($hostname, 4);

if (file_exists("/srv/$hostname")) {
        // Show an actual 404
        <html><head><title>404 Not Found</title></head><body>The requested file was not found.</body></html>
} else {
        // Cancel the 404 error

        // Show parking script etc
        Parking script here!

Your way is much nicer, thanks again!


Amazing! Glad it worked! :slight_smile:

The other files will have: DocumentRoot rather than VirtualDocumentRoot

What you have there is another alternative to doing it and some may say it’s a better way. However I like the literal thing of The domain isn’t hosted for any reason here’s the error page. The 404 could interfere with legit sites from personal experience when Apache decides to have a flap.


Ahhh I see – I’d somehow been blind to the other per-site .confs and thought that zz-mass-hosting.conf served every site under /srv itself.

All makes sense now, and thanks again!