Sam Hamilton
Sam Hamilton

Reputation: 131

setting a default apache virtual host

Is there any better way of setting the default apache virtual host other than it just picking the first config it finds?

I have a server with many domains, of which only some are configured with httpd but the default virtual host severed up is for example is aaa.com where as really I would like it to default to mmm.com instead?

Something like parking domains without going through the hassle of setting up a config for each one - then I can serve a "content this domain has not been created yet" page?

Cheers

Upvotes: 6

Views: 18915

Answers (3)

cmac
cmac

Reputation: 3268

The first sites-available conf file is default (alphabetically). There should be a 000-default.conf file already, if not create it.

Edit this one to your liking and then make sure it's enabled a2ensite 000-default.conf. And apache2 is reloaded sudo service apache2 reload.

Then any request that isn't caught by your other vhosts will come here.

Upvotes: 1

leepowers
leepowers

Reputation: 38308

You can create a default virtual host and name it something like 000-default so that it loads first and is used unless another vhost matching the requested domain is found. Here's the bare-bones 000-default:

<VirtualHost *:80>
    DocumentRoot /var/www
    <Directory /var/www >
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Then you can setup a PHP file under /var/www to create a domain parking page (this is a very simplified example):

<?php

printf('The domain <b>%s</b> is being parked', 
    htmlentities($_SERVER['HTTP_HOST']));

?>

Upvotes: 12

kibitzer
kibitzer

Reputation: 4589

Use ServerAlias in a name-based VirtualHost, you will only have to add one line per each new domain.

Upvotes: 0

Related Questions