LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
  Search this Thread
Old 11-17-2008, 08:54 AM   #1
ptemmerman
Member
 
Registered: Oct 2008
Location: Spain
Distribution: Ubuntu
Posts: 75

Rep: Reputation: 15
Question Rewrite URL path in reversed proxy setup


Hi all.

I have an Apache server that takes care of load balancing four Tomcat servers, using mod_proxy.
The four Tomcat servers are setup in two clusters:

cluster1: 2 Tomcats 5.5.7
cluster2: 2 Tomcats 5.5.27

Now, I have depending on the application that is being requested, the request should be send to cluster1 or cluster2.
I have this setup working using the <Location> tag.

Code:
<Proxy balancer://mycluster1>
        BalancerMember ajp://172.18.0.39:8009 route=vdebian1
        BalancerMember ajp://172.18.0.40:8009 route=vdebian2
</Proxy>

<Proxy balancer://mycluster2>
        BalancerMember ajp://172.18.0.78:8009 route=vdebian3
        BalancerMember ajp://172.18.0.84:8009 route=vdebian4
</Proxy>

<Location /SEDO>
       ProxyPass balancer://mycluster1 stickysession=JSESSIONID
       ProxyPassReverse /
</Location>

<Location /SEDO-NEW>
       ProxyPass balancer://mycluster2 stickysession=JSESSIONID
       ProxyPassReverse /
</Location>
This works perfectly as I expected. However, the problem I have is that some images or links on my webapp are specified relatively.
For example <img href="image.gif">, which results in errors because the image cannot be found on the root of my server, which is logical.

So, I thought I'd use the following:

Code:
<LocationMatch ^(.*\.gif)$>
        ProxyPassMatch balancer://mycluster1/$1
</LocationMatch>
However, the problem is that I do not know to which application the image belongs, thus I don't know either to which cluster I should proxy the request.
So I thought using mod_proxy_html to rewrite the URLs in the HTML files:

Code:
<Location /SEDO>
       ProxyPass balancer://mycluster1 stickysession=JSESSIONID
       ProxyPassReverse /
       SetOutputFilter proxy-html
       ProxyHTMLURLMap (.*\.gif) http://172.18.0.39:8080/$1 Rie
</Location>
This works, however, what I do not like is that I map the URLs to a hardcoded server. What if the Tomcat instance is down? Then my images won't be loaded.
As far as I tried, it is also impossible to specify a cluster path as URL.

Thus, my question folks, how can I solve this? I've been thinking about using Vhosts, but I don't know if that would be the right solution. Maybe there is something easier, such as altering a HTTP reponse header in order to know which webapp requested the image.

Any help will be kindly appreciated.
 
Old 11-18-2008, 06:53 AM   #2
ptemmerman
Member
 
Registered: Oct 2008
Location: Spain
Distribution: Ubuntu
Posts: 75

Original Poster
Rep: Reputation: 15
This is solved.
In order to help other people with the same problem, I will describe the cause and give the solution.

PROBLEM:

When the browser sees a resource in a HTML file, such as <img href="image.gif", then it takes the current URL and removes the last part of the URL upto the slash.

Let's assume the URL is:
http://172.18.0.1/SEDO

In order to retrieve the relative image, the browser removes the last part of the URL, which would make it something like this:

http://172.18.0.1/image.gif

And this is where the problem resides. That particular image cannot be found at that location.

SOLUTION:
Rewrite all URLs to contain a trailing slash.

Code:
RewriteEngine On
RewriteRule ^/([^/\.]+)$ $1/ [R=301,L]
The URL http://172.18.0.1/SEDO will now be rewritten to http://172.18.0.1/SEDO/. When the browser sees the <img> tag with a relative path, it will remove the last part of the URL upto the slash, and insert the image name. This would be:

http://172.18.0.1/SEDO/image.gif

And tataa, it works!
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
rewrite rule base url apache2 sinister1 Linux - Software 3 11-23-2007 10:17 AM
URL rewrite help needed rino.caldelli Linux - Server 4 09-28-2007 04:19 PM
Mod REWRITE url rewriting gabsik Linux - Networking 1 09-29-2006 05:24 AM
apache url rewrite gallew Linux - Server 0 08-25-2006 03:54 AM
Use apache to rewrite to external server and keep same browser URL ijsman77 Linux - Software 1 04-09-2004 07:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:35 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