This question may be more appropriate for the Apache mailing list, but it is Zope-related so I figured I'd check here as well. I'm trying to set up Apache HTTP Server to run in front of three sites on my server. Two of which are Zope sites and one of which is a PHP app that is hosted by Apache. I've got three different URLs pointing to the IP address of the server. The setup is something like this: Zope Site 1 - Actual address: www.mysite.com:1234/zope1 Virtual Host: zope1.mysite.com (Zope is running on port 1234) Zope Site 2 - Actual address: www.mysite.com:1234/zope2 Virtual Host: zope2.mysite.com PHP Site - Actual address: www.mysite.com:7777 Virtual Host: php.mysite.com Now here's the frustrating part - I've got it working perfectly as long as I'm accessing these sites from the server. The problem is, whenever I try to access zope1.mysite.com or zope2.mysite.com from another machine, it sends me to php.mysite.com. Any ideas? Here's my virtual host configuration: NameVirtualHost zope1.mysite.com:80 <VirtualHost zope1.mysite.com:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope1.mysite.com/zope1/VirtualHos... [L,P] </VirtualHost> NameVirtualHost zope2.mysite.com:80 <VirtualHost zope2.mysite.com:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope2.mysite.com/zope2/VirtualHos... [L,P] </VirtualHost> NameVirtualHost php.mysite.com <VirtualHost php.mysite.com> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:7777/$1 [L,P] </VirtualHost>
You've got the syntax completely wrong for name based virtual hosts, you've done it for IP based virtual hosts, in which case the last definition of the vhost for the ip address takes effect.
NameVirtualHost zope1.mysite.com:80
The NameVirtualHost directive specifies the IP address Apache runs the name based virtual host check on. On a host with only one IP address, or multiple that should point to the same site, it goes like this: NameVirtualHost *:80
<VirtualHost zope1.mysite.com:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope1.mysite.com/zope1/VirtualHos... [L,P] </VirtualHost>
The value in the VirtualHost 'tag' is the _IP ADDRESS_ that the virtual host runs on, not the server name. This config will work: NameVirtualHost *:80 <VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope1.mysite.com/zope1/VirtualHos... $1 [L,P] </VirtualHost> <VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope2.mysite.com/zope2/VirtualHos... [L,P] </VirtualHost> <VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:7777/$1 [L,P] </VirtualHost> -- Phillip Hutchings http://www.sitharus.com/ sitharus@gmail.com / sitharus@sitharus.com
On 16.Jan 2005 - 23:14:01, Phillip Hutchings wrote:
You've got the syntax completely wrong for name based virtual hosts, you've done it for IP based virtual hosts, in which case the last definition of the vhost for the ip address takes effect.
Yes there are some errors, but...
NameVirtualHost zope1.mysite.com:80
The NameVirtualHost directive specifies the IP address Apache runs the name based virtual host check on. On a host with only one IP address, or multiple that should point to the same site, it goes like this: NameVirtualHost *:80
Correct.
<VirtualHost zope1.mysite.com:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope1.mysite.com/zope1/VirtualHos... [L,P] </VirtualHost>
The value in the VirtualHost 'tag' is the _IP ADDRESS_ that the virtual host runs on, not the server name. This config will work:
Not if he wants to do name-based virtual hosts and thats probably what he wants, as the following doesn't make any sense at all...
NameVirtualHost *:80
<VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope1.mysite.com/zope1/VirtualHos... $1 [L,P] </VirtualHost>
<VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:1234/VirtualHostBase/http/zope2.mysite.com/zope2/VirtualHos... [L,P] </VirtualHost>
<VirtualHost *:80> ServerName www.mysite.com RewriteEngine On RewriteRule ^/(.*) http://127.0.0.1:7777/$1 [L,P] </VirtualHost>
This doesn't make any sense and even though I'm not a apache-pro I don't think its correct at all. How does apache decide which VirtualHost to use? For the OP, if you use only the following NameVirtualHost and leave the rest as is, it should work: NameVirtualHost *:80 Andreas -- Don't plan any hasty moves. You'll be evicted soon anyway.
This doesn't make any sense and even though I'm not a apache-pro I don't think its correct at all. How does apache decide which VirtualHost to use?
It matches the Host: header against the ServerName attribute. See http://httpd.apache.org/docs-2.0/vhosts/name-based.html, it's the same for 1.3 as well.
For the OP, if you use only the following NameVirtualHost and leave the rest as is, it should work:
NameVirtualHost *:80
That will work as well, but only because the separate hostnames point to the same IP address. The attribute in the VirtualHost 'tag' specifies the IP address to bind the virtual host definition to, in the case of name-based you just assign the same IP to all the hosts on that IP address. -- Phillip Hutchings http://www.sitharus.com/ sitharus@gmail.com / sitharus@sitharus.com
participants (3)
-
Andreas Pakulat -
Phillip Hutchings -
Robert Hill