top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Apache: Name based virtualhosts with default

+1 vote
393 views

I was reading the documentation and testing out some things. We have multiple name based virtual hosts, but would like to display a page when not match is found.
According to the documentation at [http://httpd.apache.org/docs/2.2/vhosts/name-based.html] and [https://httpd.apache.org/docs/2.4/vhosts/name-based.html#defaultvhost], the first matching servername or alias is used, with no precedence for wildcards.

What appears to be working in our case is a 'default' host with 'ServerName *', but how would I know for certain that this is the one that is always used?

Our configuration has the typical include of "/etc/httpd/conf.d/*.conf", it is here that the vhosts are defined in separate files. Should the default also be placed in here or does it have to be defined at the end of the httpd.conf (master) configuration file?

It is currently my understanding that I should place it at the bottom of httpd.conf; so to be sure it is that last that is matched, but I would like to hear from someone with more knowledge and/or experience about apache than myself. I would prefer it to be placed in the conf.d folder if possible.

posted Oct 1, 2013 by Ahmed Patel

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

It might depend on which distribution you are using. Some systems (Debian, for example) will always load the config files in alphabetical order, so the default vhost is usually named 000-default to ensure it loads first. I dont think you can guarantee that on other systems.

If you do decide to include the default vhost in the httpd.conf, you would need to put it before the line that includes conf.d

answer Oct 1, 2013 by Sumit Pokharna
Similar Questions
+1 vote

I am courious if there are others who have the same observation in my case. I used the Apache documentation to use name based virtual hosts.

My site-enabled file looks now like this:

NameVirtualHost *:80

 ServerName wiki.mydomain.com
 ServerAdmin webmaster@mydomain.com
 DocumentRoot /var/lib/wiki/

 Options +FollowSymLinks
 AllowOverride All
 order allow,deny
 allow from all

 ServerName www.mydomain.com
 ServerAlias *.mydomain.com
 ServerAdmin webmaster@localhost

 DocumentRoot /var/www

 Options FollowSymLinks
 AllowOverride None

 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all

 ErrorLog /var/log/apache2/error.log    
 LogLevel warn    
 CustomLog /var/log/apache2/access.log combined

I want to achieve that wiki.mydomain.com loads the wiki directly, thus the 1st virtual host. All other *.mydomain.com hosts shall be handled by the 2nd virtual host.

Actually, it works (on the surface?), but I get this warning when I restart acpache2:

# service apache2 restart
 * Restarting web server apache2
[Mon Sep 09 11:05:03 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
 ... waiting 
[Mon Sep 09 11:05:04 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
 ...done.

What does the warning really mean?
I have specified Virtual Hosts with pattern *:80, they are apparently working, but why the warning then? How could I change my configuration to make the warning disappear?

0 votes

I am using Apache 2.2 on LE for several years now and I use intensively the virtual host mechanism (300 virtual hosts per http instance).

As soon as you start sharing resources between applications, you want to protect your platform and prevent an application from taking all the threads and cause a resource starvation for the others.

To do so i used the third party mod_qos module to limit the number of simultaneous connections per virtual hosts. Now that i intend to migrate to Apache 2.4, my first tests reveal that this module is not compatible with this version of Apache, thats also the warning that developer raised for his module.

It appears that I don't find any real alternative to substitute the mod_qos module with something else. Here are my questions :
- Can you confirm that Apache does not provide any mechanism allowing to limit the number of connection per virtual host, just to be sure that I am not missing something ?
- Why Apache doesn't provide such a functionality ? :) From my very humble user perspective, I am surprised that this is not a native functionality as it seems to me that my need is probably shared by many users. Moreover Apache provides many other complex functionalities, the one I am describing would be probably something simple to implement compared to other functionalities already available.

+2 votes

I want to run three virtual hosts on separate IP addresses for notification messages (the reason is due to how the network kit does the redirection of traffic)

On each of these virtual hosts I want a request for any URI to be sent to the document root default (/index.html or just /)

What the best way to achieve this per virtual host?

+1 vote

I try to configure apache virtual hosts after NAT. There are two name (like abc.dom.com and cde.dom.com) which refer to the same external address. This address is given to wan-port of a gateway and assigned to
be NAT to internal address where apache is up with ports 80 to 80.

Does it possible to configure the apache so it distinguishes name abc.* and cde.* (used by clients externally) and returns different pages (provided two s are configured)?

Which Directives are implemented in the case? Or, maybe, the example of such httpd.conf?

...