LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache reverse proxy problem with vhost (http://www.linuxquestions.org/questions/linux-software-2/apache-reverse-proxy-problem-with-vhost-929439/)

omgs 02-15-2012 05:43 AM

Apache reverse proxy problem with vhost
 
Hi.

I'm on the way to migrate a remote old site in our domain from the server which currently resides (and I have no access) to our servers. I want to keep the access after the migration using a different url. This is a vhost, so, AFAIK, it's currently accessed only by the configured server name. So, if right now I intend to use http://<samename>/oldsite to access http://currenthost/site, I do this in my apache:

<VirtualHost *:80>

[Initial apache staff]

ProxyRequests Off

<Location /oldsite/>
Order deny,allow
Allow from all
ProxyPassReverseCookieDomain <CURRENTIP> <CURRENTHOSTNAME>
ProxyPass http://<CURRENTIP>/site/
ProxyPassReverse http://<CURRENTIP>/site/
ProxyPassReverseCookiePath /site/ /oldsite/
</Location>
</VirtualHost>

This fails because the server is accessed via http://CURRENTIP/site, and the domain name is not set (theorically sent in ProxyPassReverseCookieDomain). I've tried reversing the arguments in this Directive and others, but the result is always the same. I've also tried accessing by the current vhostname instead of the IP and it works, so it looks plain that the problem is the servername is not sent (I see the remote apache response stating the IP instead of the name).

What is the problem? I'm using latest Ubuntu and the apache supplied with it (2.2.20, according to the log).

acid_kewpie 02-15-2012 05:47 AM

Yo yo, Check dis - http://httpd.apache.org/docs/2.0/mod...xypreservehost

omgs 02-15-2012 06:18 AM

I was aware of that but that what does is sends the hostname used, not a specific hostname, so it doesn't solve my problem.

acid_kewpie 02-15-2012 06:48 AM

Dammit.

OK, well presuming this is only a single hostname to hit, why not just add the hostname to the servers own /etc/hosts file and use the server name in the proxy pass? It's a little hacky, but it should work just fine.

omgs 02-15-2012 07:07 AM

I already thought about it, but I can't do that because in the future I will take the hostname to replace the service in a transparent way, so it's not a safe option.

acid_kewpie 02-15-2012 07:56 AM

OK , 3rd time lucky! use mod_rewrite to mangle the Host header? http://infinitesteps.blogspot.com/20...st-header.html

omgs 02-15-2012 11:01 AM

I've commented all the above and used these lines instead:

RewriteEngine On
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9
RewriteCond %{REQUEST_URI} ^/oldsite/(.*)$
RequestHeader set Host CURRENTHOST
RewriteRule ^/oldsite/(.*)$ http://CURRENTIP/site/$1 [P]

And the log:

127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (2) init rewrite engine with requested uri /oldwiki/index.php
127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (3) applying pattern '^/oldsite/(.*)$' to uri '/oldsite/index.php'
127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (4) RewriteCond: input='/oldsite/index.php' pattern='^/oldsite/(.*)$' => matched
127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (2) rewrite '/oldsite/index.php' -> 'http://CURRENTIP/site/index.php'
127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (2) forcing proxy-throughput with http://CURRENTIP/site/index.php
127.0.0.1 - - [15/Feb/2012:16:51:15 +0100] [localhost/sid#b73c7518][rid#b6d59058/initial] (1) go-ahead with proxy request proxy:http://CURRENTIP/site/index.php [OK]

The result is exactly the same (i.e., taking the ip instead of the hostname). I've tried commenting the RewriteCond line, but there's no difference.

What is wrong?

acid_kewpie 02-15-2012 01:58 PM

You'd want to do the ProxyPreserveHost stuff as well I think.

omgs 02-15-2012 03:27 PM

Thanks, that did the trick (not mentioned in the examples). Now everything works. This is the current section of my apache at localhost, to test both sites (they are wikis):

ProxyRequests Off
ProxyPreserveHost On

<Location /oldwiki/>
Order deny,allow
Allow from all
ProxyPass http://CURRENTIP/wiki/
ProxyPassReverse http://CURRENTIP/wiki/
RequestHeader set Host "wiki.oldhost.net"
</Location>

<Location /wiki/>
Order deny,allow
Allow from all
ProxyPass http://NEWIP/wiki/
ProxyPassReverse http://NEWIP/wiki/
RequestHeader set Host "wiki.newhost.net"
</Location>

Just mention that NEWIP is defined in my /etc/hosts file (currently, the DNS points to a wildcard with a different ip).


All times are GMT -5. The time now is 07:55 AM.