Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: redirection of apache2 problem Debian Lenny |
|
Author |
|
velocity
Joined: 14 Apr 2010 Posts: 21
|
Posted: Wed 28 Apr '10 15:04 Post subject: redirection of apache2 problem Debian Lenny |
|
|
Hi,
I have a webserver apache2 on debian Lenny.
I am using gateway as Dom0 and rest of the operating systems are different Dom's .Using a xen virtualization setup.
I want to have a few websites
http://site1.myserver.com
http://myserver.com
and http://myserver.com/site2
I did set up a reverse proxy environment for doing this.
Code: |
Dom0 LAN IP ----> 192.168.1.1 Gateway (where reverse proxy is set)
DomU1 LAN IP ----> 192.168.1.13 ( here myserver.com
and site1.myserver.com
both are hosted.)
Domu2 LAN IP ----> 192.168.1.17 myserver.com/site2 is here. |
Configuration on Dom0 of sites site1.myserver.com and myserver.com
Virtual Host Configurations on Dom0
in /etc/apache2/sites-enabled/myserver.com (on gateway)
Code: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myserver.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.1.13/
ProxyPassReverse / http://192.168.1.13/
ProxyPass /site2 http://192.168.1.17/
ProxyPassReverse /site2 http://192.168.1.17/
</VirtualHost>
|
then /etc/apache2/sites-enabled/site1.myserver.com (on gateway)
has
Code: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site1.myserver.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.1.13/
ProxyPassReverse / http://192.168.1.13/
</VirtualHost>
|
and following asci chart
Code: |
On Dom0
sites-enabled
|
|--------------->myserver.com (ProxyPass / to http://192.168.1.13/)
|
|--------------->site1.myserver.com (ProxyPass / to http://192.168.1.13/)
|
and for myserver.com/site2
on Dom0 in same file I have following
Code: |
ProxyPass /site2 192.168.1.17
ProxyPassReverse /site2 192.168.1.17
|
On DomU (site1) 192.168.1.13 where site1.myserver.com and myserver.com are actually present.
Code: |
sites-enabled
|
|--------------->myserver.com (DocumentRoot /var/www/myserver)
|
|--------------->site1.myserver.com (DocumentRoot /var/www/site1)
|
Is this configuration wrong.
What is happening is
if some one clicks on http://myserver.com or http://site1.myserver.com he sees http://site1.myserver.com
Which should not happen.
Scene 2)
If you open
http://myserver.com/site2
Following comes
Code: |
Not Found
The requested URL /site2 was not found on this server.
|
Configuration is
Code: |
On Dom0
sites-enabled in same file myserver.com
|
|--------------->myserver.com (ProxyPass /site2 to http://192.168.1.17/)
(ProxyPassReverse /site2 http://192.168.1.17/)
|
http://myserver.com/site2 is not opening.
On DomU that is 192.168.1.13 where site1.myserver.com and myserver.com are hosted
I have
/etc/apache2/sites-enabled/site1.myserver.com (where it is hosted on LAN)
Code: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myserver.com
DocumentRoot /var/www/mainsite/
<Directory /var/www/ >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
|
and /etc/apache2/sites-enabled/myserver.com (where it is hosted on LAN)
Code: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site1.myserver.com
DocumentRoot /var/www/site1/
<Directory /var/www/ >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
|
and configuration of myserver.com/site2 on 192.168.1.17
Code: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myserver.com/site2
DocumentRoot /var/www
<Directory /var/www/ >
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
|
So what should I check in? |
|
Back to top |
|
velocity
Joined: 14 Apr 2010 Posts: 21
|
Posted: Thu 29 Apr '10 14:28 Post subject: |
|
|
I have found some thing which may help
apache2 when has 2 vhosts on same IP serves them in alphabetical order
that is why installation of apache2 has 000-default as a vhost
http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1
On apache2 documentation last example Using the ServerPath directive
on following link
http://httpd.apache.org/docs/2.0/vhosts/examples.html#page-header
says Code: | "To provide as much backward compatibility as possible we create
a primary vhost which returns a single page containing links with an
URL prefix to the name-based virtual hosts."
|
so I infer we should have one more file on DomU site1 which
separates myserver.com and site1.myserver.com vhosts although right
now there are 2 files but I think there should be one more file
since in url myserver.com and site1.myserver.com
alphabetically myserver.com is coming first and so it is being served always.
Since the gatway is forwarding both the requests to internal machine whose IP is 192.168.1.13
and when it is giving response it is by default serving the page which alphabetically is coming first so I am seeing both the websites as same pages.
Since to the gateway is forwarding both request
(site1.myserver.com and myserver.com )
to IP 192.168.1.13
and apache2 on 192.168.1.13 is serving vhost requests in alphabetical order.
As an idea if I configure on internal domu1 myserver.com on a different port then it may work but I do not want to do that.
In case you feel my observation is right let me know. |
|
Back to top |
|
velocity
Joined: 14 Apr 2010 Posts: 21
|
Posted: Fri 30 Apr '10 8:47 Post subject: |
|
|
Finally I got every thing working.
I have found some thing which may help
apache2 when has 2 vhosts on same IP serves them in alphabetical order
that is why installation of apache2 has 000-default as a vhost
http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1
On apache2 documentation last example Using the ServerPath directive
on following link
http://httpd.apache.org/docs/2.0/vhosts/examples.html#page-header
says Code: | "To provide as much backward compatibility as possible we create
a primary vhost which returns a single page containing links with an
URL prefix to the name-based virtual hosts."
| so I infer we should have one more file on DomU site1 which
separates myserver.com and site1.myserver.com vhosts although right
now there are 2 files but I think there should be one more file
since in url myserver.com and site1.myserver.com
alphabetically myserver.com is coming first and so it is being served always.
Since the gatway is forwarding both the requests to internal machine whose IP is 192.168.1.13
and when it is giving response it is by default serving the page which alphabetically is coming first so I am seeing both the websites as same pages.
Since to the gateway is forwarding both request
(site1.myserver.com and myserver.com )
to IP 192.168.1.13
and apache2 on 192.168.1.13 is serving vhost requests in alphabetical order.
As an idea if I configure on internal domu1 myserver.com on a different port then it may work but I do not want to do that.
In case you feel my observation is right let me know.[/QUOTE]
I am posting the findings of all what it made work.
The solution for above error came by adding
ServerName directive on DomU1 also adding the corresponding thing to /etc/hosts on Dom0
and in the sites-enabled where ProxyPass and ProxyPassReverse is mentioned
<VirtualHost *:80>
# do not mention IP read the note below
ProxyPass / http://servername where redirected
ProxyPassReverse / http://servername where redirected
</VirtualHost>
Read this note it is important
Do not use the IP here if more than one site is on the DomU
What happens is when you put up the IP address in Dom0 as above then the server which will recieve request will server you a vhost which is present alphabeticaly first in its sites-enabled directory.
To get rid of this you need to have on your gateway or Dom0
a DNS if you do not have then use /etc/hosts to map internal servers by name.
Code: |
/etc/hosts/
192.168.1.13 abc1 abc2
192.168.1.17 abc3
192.168.1.18 abc4
| Now your Dom0 or Gateway is aware of abc1 abc2 abc3 and abc4 are which IP internally mapped to.Do not thing that putting abc1 and abc2 above is a mistake .
I redirected two pages from main site to ip 192.168.1.13 internally
the scenario is your main site itself is on an internal machine which is accessible by a gateway redirecting the requests to it.
Now you have to do some home work on Dom1 at 192.168.1.13 where your sites are hosted in the vhost configuration file write
and in another host write
ServerName directive will serve the vhost request based on the servers name.
Otherwise vhosts will be served in alphabetical order.
Thanks for your help. |
|
Back to top |
|
|
|
|
|
|