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: Problems setting up Reverse Proxy in Apache |
|
Author |
|
mike_hance
Joined: 06 Apr 2015 Posts: 1 Location: United States
|
Posted: Mon 06 Apr '15 21:28 Post subject: Problems setting up Reverse Proxy in Apache |
|
|
I'm currently in the process of configuring a red hat linux server as a proxy server for a number of back end web servers. I set up reverse proxying to hide the web server url's, but I've run into a problem with the second web server, because some of the directory structures are identical on both servers.
Below is a snippet of the portion I'm having problems with.
Code: |
RewriteEngine On
RewriteRule ^/images(.*) /test/images$1 [L,P]
RewriteRule ^/skins(.*) /test/skins$1 [L,P]
RewriteRule ^/index.php(.*) /test/index.php$1 [L,P]
RewriteRule ^/images(.*) /test1/images$1 [L,P]
RewriteRule ^/skins(.*) /test1/skins$1 [L,P]
RewriteRule ^/index.php(.*) /test1/index.php$1 [L,P]
<Location /test>
ProxyPass https://myserver.com
ProxyPassReverse https://myserver.com
</Location>
<Location /test1>
ProxyPass https://myserver2.com
ProxyPassReverse https://myserver2.com
</Location>
|
The problem I'm having is that the directory structure is the same on both servers, so there are images and skins directories on both. I can get to the each server with no problem by using https://proxyserver.com/test or https://proxyserver.com/test1, but if I try clicking on links within the site it is always using the images or skins directories for test (myserver.com) even if it should be going to test1 (myserver2.com). The rewrite rules are there to tell the proxy server to look for those directories on the web server as opposed to the proxy server. I don't see anything in the apache GET message or any of the server variables that distingquishes the traffic as coming from myserver versus myserver2. I've tried manually setting an environment variable based on the initial url, but the variable doesn't persist with the subsequent traffic.
Any help would be greatly appreciated! |
|
Back to top |
|
Jens_S
Joined: 16 Apr 2015 Posts: 3 Location: Germany, Bonn
|
Posted: Thu 16 Apr '15 15:55 Post subject: Re: Problems setting up Reverse Proxy in Apache |
|
|
My suggestion is:
Code: |
RewriteEngine On
RewriteRule ^/images(.*) /test/images$1 [L,P]
RewriteRule ^/skins(.*) /test/skins$1 [L,P]
RewriteRule ^/index.php(.*) /test/index.php$1 [L,P]
|
^^^ at this point, the url e.g. ^/images(.*) is rewritten to /test/images$1.
Code: |
RewriteRule ^/images(.*) /test1/images$1 [L,P]
RewriteRule ^/skins(.*) /test1/skins$1 [L,P]
RewriteRule ^/index.php(.*) /test1/index.php$1 [L,P]
|
^^^ these rewrites never match as they are already rewritten to something else on /test/.
lets say you try to open
/images/icon.png
then its rewritten to
/test/images/icon.png
before the second RewriteRule for /test1/ is called. So "^/images" can never match at this point. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 16 Apr '15 16:51 Post subject: |
|
|
What you are trying to do is not possible in that way.
You may have two vhosts with different subdomain to get it working.
Or you have to rename the directories ... |
|
Back to top |
|
|
|
|
|
|