Setting apache virtual host by default

Is there a better way to set apache default virtual host, except that it just selects the first configuration that it finds?

I have a server with many domains, of which only some are configured using httpd, but the virtual host is disabled by default, for example, aaa.com, where, as in fact, I would like it to be the default instead mmm.com?

Something like parking domains, without affecting the configuration settings for each of them - then can I serve the page "content that this domain has not yet been created"?

Greetings

+6
apache
source share
3 answers

You can create a default virtual host and call it something like 000-default so that it boots first and is used if no other vhost matching the requested domain is found. Here the bare bones are 000-default :

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

Then you can configure the 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'])); ?> 
+8
source share

The first site is the default conf file (in alphabetical order). There must be a 000-default.conf file if it is not created.

Change it to your liking and then make sure it is enabled by a2ensite 000-default.conf . And apache2 reboots sudo service apache2 reload .

Then any request that is not caught by your other ghosts will come here.

+1
source share

To use ServerAlias ​​in a name-based virtual host, you will only need to add one row for each new domain.

0
source share

All Articles