LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-28-2010, 07:37 AM   #1
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Rep: Reputation: 39
URL redirection problem in a reverse proxy apache2 environment on Lenny with Xen


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?

Last edited by tkmsr; 04-28-2010 at 08:34 AM.
 
Old 04-28-2010, 01:56 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

It seems you make it more and more complicated!

Quote:
What is happening is
if some one clicks on http://myserver.com or http://site1.myserver.com he sees http://site1.myserver.com
You have:
Quote:
ProxyPass / http://192.168.1.13/
for both myserver.com and site1.myserver.com, so this is expected behavior.You should use hostnames instead of ip addresses, but without some sort of name server using split views, I really don't know how you (i.e. the gateway box) can distinguish the internal and external myserver.com and site1.myserver.com.

Quote:
and configuration of myserver.com/site2 on 192.168.1.17

Code:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myserver.com/site2
This is not a valid server name (I wonder why apache does not complain). Use "ServerName site2.myserver.com" instead
 
Old 04-28-2010, 11:27 PM   #3
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by bathory View Post
for both myserver.com and site1.myserver.com, so this is expected behavior.You should use hostnames instead of ip addresses,
You mean to say hostnames in ProxyPass directives
I did so.
In my gateway I did
/etc/hosts
Code:
192.168.1.13 site1.myserver.com site1.myserver.com
192.168.1.13 myserver.com myserver.com
192.168.1.17  site2  myserver.com/site2
and on router
/etc/apache2/sites-enabled/myserver.com
Code:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName myserver.com
        ProxyRequests off
        <Proxy *>
        Order deny,allow
        Allow from all
        </Proxy>
        ProxyPass / http://myserver.com
        ProxyPassReverse / http://myserver.com
        ProxyPass /site2 http://site2
        ProxyPassReverse /site2 http://site2
</VirtualHost>
and /etc/apache2/sites-enabled/site1.myserver.com
Code:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName site1.myserver.com
        ProxyRequests off
        <Proxy *>
        Order deny,allow
        Allow from all
        </Proxy>
        ProxyPass / http://site1.myserver.com
        ProxyPassReverse / http://site1.myserver.com
</VirtualHost>
after this both the domains stopped working.
I got following error
Code:
Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /.

Reason: Error reading from remote server
Quote:
Originally Posted by bathory View Post
This is not a valid server name (I wonder why apache does not complain). Use "ServerName site2.myserver.com" instead
Yes it did complained.

Last edited by tkmsr; 04-29-2010 at 12:49 AM.
 
Old 04-29-2010, 12:48 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
In my gateway I did
/etc/hosts
Code:

192.168.1.13 site1.myserver.com site1.myserver.com
192.168.1.13 myserver.com myserver.com
192.168.1.17 site2 myserver.com/site2

and on router
/etc/apache2/sites-enabled/myserver.com
Code:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myserver.com
...
ProxyPass / http://myserver.com
ProxyPassReverse / http://myserver.com
---<snip>---
and /etc/apache2/sites-enabled/site1.myserver.com
Code:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site1.myserver.com
...
ProxyPass / http://site1.myserver.com
ProxyPassReverse / http://site1.myserver.com
I don't see how this is going to work. The gateway (the same as router) box has 2 vhosts to proxy to themselves!!!

Quote:
Yes it did complained but I ignored that thanks for this one I have corrected it.
But you have:
Quote:
192.168.1.17 site2 myserver.com/site2
in /etc/hosts
 
Old 04-29-2010, 01:47 AM   #5
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by bathory View Post
I don't see how this is going to work. The gateway (the same as router) box has 2 vhosts to proxy to themselves!!!
Hmmm I feel you are right.
I am posting the output of what I have tried

on router. (router gateway are both same)
/etc/apache2/sites-enabled/myserver.com
Code:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName myserver.com
        ProxyRequests off
        <Proxy *>
        Order deny,allow
        Allow from all
        </Proxy>
        ProxyPass / http://site1
        ProxyPassReverse / http://site1
        ProxyPass /site2 http://site2
        ProxyPassReverse /site2 http://site2
</VirtualHost>
in fact on above file I have tried four combinations


First configuration which did not worked on Dom0 myserver.com
Code:
ProxyPass / http://192.168.1.13
ProxyPassReverse / http://192.168.1.13
Second configuration which did not worked on Dom0 myserver.com
Code:
ProxyPass / http://site1
ProxyPassReverse / http://site1
Third configuration which did not worked on Dom0 myserver.com
Code:
ProxyPass / http://site1/var/www/main/
ProxyPassReverse / http://site1/var/www/main/
Fourth configuration which did not worked on Dom0 myserver.com
Code:
ProxyPass / http://192.168.1.13/var/www/main/
ProxyPassReverse / http://192.168.1.13/var/www/main/

and /etc/hosts on gateway (Dom0)
Code:
192.168.1.13 site1.myserver.com site1
192.168.1.17 myserver.com/site2 site2

Last edited by tkmsr; 04-29-2010 at 01:53 AM.
 
Old 04-29-2010, 02:13 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
May I ask why don't you use different host names for the internal web servers?
And for the 3rd time
Quote:
192.168.1.17 myserver.com/site2 site2
is not a valid hostname
 
Old 04-29-2010, 05:34 AM   #7
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by bathory View Post
May I ask why don't you use different host names for the internal web servers?
That is not in my hands I have to take permission to do that.
Since you have read all my previous posts the previous settings were all working properly.

In a previous post which you replied for Drupal
Code:
http://myserver.com/site1
http://myserver.com/site2
http://myserver.com/site3
http://myserver.com/site4
the above setup was working perfectly fine.
I will surely try to get the internal hostnames changed if that is the reason you feel.

Last edited by tkmsr; 04-29-2010 at 05:41 AM.
 
Old 04-29-2010, 06:17 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
It was working because you were using IPs instead of vhosts with same names as the backend servers.
If you cannot change hostnames, better stick with the IPs

Regards
 
Old 04-29-2010, 07:08 AM   #9
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by bathory View Post
It was working because you were using IPs instead of vhosts with same names as the backend servers.
If you cannot change hostnames, better stick with the IPs

Regards
You are right
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...irtual-hosts-1


On apache2 documentation last example Using the ServerPath directive
on following link
http://httpd.apache.org/docs/2.0/vho...ml#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.

Last edited by tkmsr; 04-29-2010 at 07:28 AM.
 
Old 04-29-2010, 07:51 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
I don't think this is going to work.
Why don't you use the 2 vhosts in the gateway to redirect requests based on the uri?

Code:
On Dom0 
	sites-enabled
	  |
	  |--------------->myserver.com      (ProxyPass / to http://192.168.1.13/)      
          |                                  (ProxyPass /site2 http://192.168.1.17/site2)
	  |
	  |--------------->site1.myserver.com (ProxyPass / to http://192.168.1.13/site1)

Last edited by bathory; 04-29-2010 at 04:48 PM.
 
Old 04-30-2010, 01:42 AM   #11
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Finally I got every thing working.
Thanks for your help and support.

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
Code:
	ServerName abc1
and in another host write
Code:
	ServerName abc2
ServerName directive will serve the vhost request based on the servers name.
Otherwise vhosts will be served in alphabetical order.
Thanks for your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 SSL Reverse Proxy doublejoon Linux - Networking 4 08-04-2011 09:29 AM
[SOLVED] Setting environment variable Lenny did not worked in .bashrc 2.6.26-2-xen-amd64 tkmsr Debian 2 04-28-2010 08:26 AM
Apache Vhost with reverse proxy and redirection volga629 Linux - Server 3 01-13-2010 03:30 AM
configure reverse proxy and apache2 hobbitmage Linux - Newbie 2 07-04-2009 05:21 PM
Apache2.2 as reverse proxy 4play Linux - Server 1 06-25-2009 12:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration