LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 02-15-2012, 04:43 AM   #1
omgs
Member
 
Registered: Dec 2010
Posts: 64

Rep: Reputation: 6
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).

Last edited by omgs; 02-15-2012 at 04:45 AM.
 
Old 02-15-2012, 04:47 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,345

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
Yo yo, Check dis - http://httpd.apache.org/docs/2.0/mod...xypreservehost
 
Old 02-15-2012, 05:18 AM   #3
omgs
Member
 
Registered: Dec 2010
Posts: 64

Original Poster
Rep: Reputation: 6
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.
 
Old 02-15-2012, 05:48 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,345

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
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.
 
Old 02-15-2012, 06:07 AM   #5
omgs
Member
 
Registered: Dec 2010
Posts: 64

Original Poster
Rep: Reputation: 6
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.
 
Old 02-15-2012, 06:56 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,345

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
OK , 3rd time lucky! use mod_rewrite to mangle the Host header? http://infinitesteps.blogspot.com/20...st-header.html
 
Old 02-15-2012, 10:01 AM   #7
omgs
Member
 
Registered: Dec 2010
Posts: 64

Original Poster
Rep: Reputation: 6
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?
 
Old 02-15-2012, 12:58 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,345

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
You'd want to do the ProxyPreserveHost stuff as well I think.
 
Old 02-15-2012, 02:27 PM   #9
omgs
Member
 
Registered: Dec 2010
Posts: 64

Original Poster
Rep: Reputation: 6
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).
 
  


Reply

Tags
apache2, cookies, domain, proxypass


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Apache Reverse Proxy - problem with configuration dlugasx Linux - Server 4 10-04-2010 06:44 AM
Apache Vhost with reverse proxy and redirection volga629 Linux - Server 3 01-13-2010 03:30 AM
Apache as Reverse Proxy LR_Brian Linux - Server 4 02-17-2009 11:33 AM
reverse proxy with apache 2 bootiack Linux - Software 1 08-09-2005 06:47 PM
apache Reverse Proxy !!!!! ashish_v Linux - Software 0 09-05-2003 04:42 PM


All times are GMT -5. The time now is 06:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration