You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ruslan Sivak <rs...@istandfor.com> on 2008/02/23 20:54:05 UTC

[users@httpd] Multiple VirtualHosts with the same name

I'm having a bit of a problem.  I  have a loadbalancer go to two virtual 
servers on one real server.  Something like

Listen 80
NameVirtualHost *:80

<VirtualHost 192.168.0.2:80>
HostName www.myhostname.com
...
</VirtualHost>


<VirtualHost 192.168.0.3:80>
HostName www.myhostname.com
...
</VirtualHost>


<VirtualHost 192.168.0.2:80>
HostName www.someotherhostname.com
....
</VirtualHost>



Hosts one and two work fine, but the third host gets matched by the 
first one.  How can I make it match properly?

Russ

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple VirtualHosts with the same name

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
> >> >>  Listen 80
> >> >>  NameVirtualHost *:80
> >> >>
> >> >>  <VirtualHost 192.168.0.2:80>
> >> >>  HostName www.myhostname.com
> >> >>  ...
> >> >>  </VirtualHost>
> >> >>
> >> >>
> >> >>  <VirtualHost 192.168.0.3:80>
> >> >>  HostName www.myhostname.com
> >> >>  ...
> >> >>  </VirtualHost>
> >> >>
> >> >>
> >> >>  <VirtualHost 192.168.0.2:80>
> >> >>  HostName www.someotherhostname.com
> >> >>  ....
> >> >>  </VirtualHost>

> >Did you actually verify that by logging it?
> >
> >Hosts 1 and 2 are IP-based virtual hosts, so the host header is irrelevant.

On 23.02.08 19:42, Ruslan Sivak wrote:
> I think therein lies the problem.  If they're IP based virtualHosts then 
> they will match everything for that ip.  As you can see Hosts 1 and 3 
> share the IP.
> 
> Here is what I want to do.  I want all the hosts to be name based 
> virtual hosts.  Hosts 1 and 2 should be on separate ips, so therefore 
> they will be hit properly from the LB.  Host 3 will have a different 
> host header so it will be matched properly too. 
> 
> How do I make a name based virtual host without having it listen on all 
> the ips?

you can listen on 0.0.0.0 but I'm afraid you have to provide each IP in
NameVirtualHost if yhou want to have name-based virtual hosts on them.

Seems that the wildcard in NameVirtualHost does not mean that every local IP
has name-based virtual hosts...
-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Due to unexpected conditions Windows 2000 will be released
in first quarter of year 1901

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple VirtualHosts with the same name

Posted by Ruslan Sivak <rs...@istandfor.com>.
Joshua Slive wrote:
> On Sat, Feb 23, 2008 at 7:31 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
>   
>> Joshua Slive wrote:
>>  > On Sat, Feb 23, 2008 at 2:54 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
>>  >
>>  >> I'm having a bit of a problem.  I  have a loadbalancer go to two virtual
>>  >>  servers on one real server.  Something like
>>  >>
>>  >>  Listen 80
>>  >>  NameVirtualHost *:80
>>  >>
>>  >>  <VirtualHost 192.168.0.2:80>
>>  >>  HostName www.myhostname.com
>>  >>  ...
>>  >>  </VirtualHost>
>>  >>
>>  >>
>>  >>  <VirtualHost 192.168.0.3:80>
>>  >>  HostName www.myhostname.com
>>  >>  ...
>>  >>  </VirtualHost>
>>  >>
>>  >>
>>  >>  <VirtualHost 192.168.0.2:80>
>>  >>  HostName www.someotherhostname.com
>>  >>  ....
>>  >>  </VirtualHost>
>>  >>
>>  >>
>>  >>
>>  >>  Hosts one and two work fine, but the third host gets matched by the
>>  >>  first one.  How can I make it match properly?
>>  >>
>>  >
>>  > What does the Host header look like when it gets to apache? I suspect
>>  > your load balancer is sending a Host header that doesn't match
>>  > www.someotherhostname.com, meaning there is no way for apache to route
>>  > it correctly.
>>  >
>>  > Joshua.
>>  >
>>
>>  The host header is fine.  The third host is not going through the lb,
>>  but is pointed directly at this server, so that wouldn't be the issue.
>>  Hosts 1 and 2 work fine, so the host header is fine there too.
>>     
>
> Did you actually verify that by logging it?
>
> Hosts 1 and 2 are IP-based virtual hosts, so the host header is irrelevant.
>
>   
I think therein lies the problem.  If they're IP based virtualHosts then 
they will match everything for that ip.  As you can see Hosts 1 and 3 
share the IP.

Here is what I want to do.  I want all the hosts to be name based 
virtual hosts.  Hosts 1 and 2 should be on separate ips, so therefore 
they will be hit properly from the LB.  Host 3 will have a different 
host header so it will be matched properly too. 

How do I make a name based virtual host without having it listen on all 
the ips?

Russ


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple VirtualHosts with the same name

Posted by Joshua Slive <jo...@slive.ca>.
On Sat, Feb 23, 2008 at 7:31 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
>
> Joshua Slive wrote:
>  > On Sat, Feb 23, 2008 at 2:54 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
>  >
>  >> I'm having a bit of a problem.  I  have a loadbalancer go to two virtual
>  >>  servers on one real server.  Something like
>  >>
>  >>  Listen 80
>  >>  NameVirtualHost *:80
>  >>
>  >>  <VirtualHost 192.168.0.2:80>
>  >>  HostName www.myhostname.com
>  >>  ...
>  >>  </VirtualHost>
>  >>
>  >>
>  >>  <VirtualHost 192.168.0.3:80>
>  >>  HostName www.myhostname.com
>  >>  ...
>  >>  </VirtualHost>
>  >>
>  >>
>  >>  <VirtualHost 192.168.0.2:80>
>  >>  HostName www.someotherhostname.com
>  >>  ....
>  >>  </VirtualHost>
>  >>
>  >>
>  >>
>  >>  Hosts one and two work fine, but the third host gets matched by the
>  >>  first one.  How can I make it match properly?
>  >>
>  >
>  > What does the Host header look like when it gets to apache? I suspect
>  > your load balancer is sending a Host header that doesn't match
>  > www.someotherhostname.com, meaning there is no way for apache to route
>  > it correctly.
>  >
>  > Joshua.
>  >
>
>  The host header is fine.  The third host is not going through the lb,
>  but is pointed directly at this server, so that wouldn't be the issue.
>  Hosts 1 and 2 work fine, so the host header is fine there too.

Did you actually verify that by logging it?

Hosts 1 and 2 are IP-based virtual hosts, so the host header is irrelevant.

One other thing to try is to list explicitly
NameVirtualHost 192.168.0.2:80

Also, I assume where you put "HostName" you actually meant "ServerName"?

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple VirtualHosts with the same name

Posted by Ruslan Sivak <rs...@istandfor.com>.
Joshua Slive wrote:
> On Sat, Feb 23, 2008 at 2:54 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
>   
>> I'm having a bit of a problem.  I  have a loadbalancer go to two virtual
>>  servers on one real server.  Something like
>>
>>  Listen 80
>>  NameVirtualHost *:80
>>
>>  <VirtualHost 192.168.0.2:80>
>>  HostName www.myhostname.com
>>  ...
>>  </VirtualHost>
>>
>>
>>  <VirtualHost 192.168.0.3:80>
>>  HostName www.myhostname.com
>>  ...
>>  </VirtualHost>
>>
>>
>>  <VirtualHost 192.168.0.2:80>
>>  HostName www.someotherhostname.com
>>  ....
>>  </VirtualHost>
>>
>>
>>
>>  Hosts one and two work fine, but the third host gets matched by the
>>  first one.  How can I make it match properly?
>>     
>
> What does the Host header look like when it gets to apache? I suspect
> your load balancer is sending a Host header that doesn't match
> www.someotherhostname.com, meaning there is no way for apache to route
> it correctly.
>
> Joshua.
>   

The host header is fine.  The third host is not going through the lb, 
but is pointed directly at this server, so that wouldn't be the issue.  
Hosts 1 and 2 work fine, so the host header is fine there too.

Russ



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple VirtualHosts with the same name

Posted by Joshua Slive <jo...@slive.ca>.
On Sat, Feb 23, 2008 at 2:54 PM, Ruslan Sivak <rs...@istandfor.com> wrote:
> I'm having a bit of a problem.  I  have a loadbalancer go to two virtual
>  servers on one real server.  Something like
>
>  Listen 80
>  NameVirtualHost *:80
>
>  <VirtualHost 192.168.0.2:80>
>  HostName www.myhostname.com
>  ...
>  </VirtualHost>
>
>
>  <VirtualHost 192.168.0.3:80>
>  HostName www.myhostname.com
>  ...
>  </VirtualHost>
>
>
>  <VirtualHost 192.168.0.2:80>
>  HostName www.someotherhostname.com
>  ....
>  </VirtualHost>
>
>
>
>  Hosts one and two work fine, but the third host gets matched by the
>  first one.  How can I make it match properly?

What does the Host header look like when it gets to apache? I suspect
your load balancer is sending a Host header that doesn't match
www.someotherhostname.com, meaning there is no way for apache to route
it correctly.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org