You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Roland Roland <R_...@hotmail.com> on 2012/07/10 16:20:58 UTC

[users@httpd] virtual host precedence ?

Can anyone help me out in understand how/why virtual host take 
precedence on the same ip ?
like i always face an issue where two distinct virtual hosts are set.
the first works, the second doesn't unless i bump it up so it becomes 
the first listed in the conf file.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host precedence ?

Posted by Norman Peelman <np...@cfl.rr.com>.
On 07/10/2012 10:20 AM, Roland Roland wrote:
> Can anyone help me out in understand how/why virtual host take 
> precedence on the same ip ?
> like i always face an issue where two distinct virtual hosts are set.
> the first works, the second doesn't unless i bump it up so it becomes 
> the first listed in the conf file.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
   The first defined/created virtual-host serves as the default when 
nothing else matches. How are you defining your virtual-hosts?
Chances are you don't have them set up correctly.

example (* matches on any IP apache is bound on.):

NameVirtualHost *
<VirtualHost *>
    # when nothing else matches ServerName or ServerAlias, apache comes here
    ServerAdmin <email address>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/path/to/files"
    DirectoryIndex index.php index.htm
...
</VirtualHost>
<VirtualHost *>
    # matches on ServerName or ServerAlias
    ServerAdmin <email address>
    ServerName example2.com
    ServerAlias www.example2.com
    DocumentRoot "/path/to/files2"
    DirectoryIndex index.php index.htm
...
</VirtualHost>
<VirtualHost *>
    # matches on ServerName or ServerAlias
    ServerAdmin <email address>
    ServerName example3.com
    ServerAlias www.example3.com
    DocumentRoot "/path/to/files3"
    DirectoryIndex index.php index.htm
...
</VirtualHost>

   The 'NameVirtualHost *' directive may be located in your main apache 
(httpd) .config file, and your VirtualHosts could be in the same file or 
a separate .config file, or individual files themselves. If all together 
then make the first one point to a default setup (site map?, redirect?). 
If individual files then make sure the default VirtualHost filename is 
something guaranteed to be loaded first, like '000-default' or similar. 
I think my initial installation came that way.

-- 
Norman
Registered Linux user #461062
-Have you been to www.apache.org yet?-

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] virtual host precedence ?

Posted by Igor Cicimov <ic...@gmail.com>.
On Wed, Jul 11, 2012 at 12:20 AM, Roland Roland <R_...@hotmail.com>wrote:

> Can anyone help me out in understand how/why virtual host take precedence
> on the same ip ?
> like i always face an issue where two distinct virtual hosts are set.
> the first works, the second doesn't unless i bump it up so it becomes the
> first listed in the conf file.
>
>
The requests for each of the domains you host will go to the appropriate
virtual host. If you are asking about the ones that don't have a virtual
host then the first VirtualHost in the config file is the default one. All
explained here: http://httpd.apache.org/docs/2.0/vhosts/name-based.html