7

** updated with workaround at bottom of this answer **

I have a requirement for my webapp to proxy to 2 external reporting servers. So I will have a menu-item for each external reporting server.

But the browser-URL has too look like it's my server so I can't just redirect. these servers both have the same context-root /ibm

For both servers browser-URL should look like http://example.com/ibm.. while the apache proxies to the correct one.

How should a setup like this be done? How can Apache know to which one it has to proxy?

I wouldn't mine if I had to do some change so the URL's would turn out like :

http://example.com/rep1/ibm and http://example.com/rep2/ibm

I managed to have the desired effect using my weblogic-proxy servlet and manipulating URL's etc, but Apache would be a more efficient solution if this can be done somehow.

I appreciate any input.

Also the inital request to the external reporting servers is launched from my webapp, not from the browser.

** update **

We now have to proxy to about 10 other webservers, where some had this issue. But whenever the target webserver was deployed in the root we also had to rewrite the body etc.. which for some of these proxy-integrations was a lot of trial and error.

Workaround Solution: we have switched to sub-domains for these proxied webservers, where actualy the subdomain URL's still point to our own apache, but using these subdomain-names we can more easily set up a virtual host & proxy in our Apache config, and we don't have to rewrite any of the response bodies etc.

2
  • Your two URL examples are identical. Could you double-check and verify them?
    – Jenny D
    Mar 20, 2014 at 16:24
  • Indeed my examples both had rep2 in URL, corrected to rep1 and rep2.
    – gotjee
    Mar 20, 2014 at 16:56

2 Answers 2

6

This is easily done with mod_proxy:

ProxyPass /rep1/ibm http://reportingserver1.example.com/ibm
ProxyPassReverse /rep1/ibm http://reportingserver1.example.com/ibm


ProxyPass /rep2/ibm http://reportingserver2.example.com/ibm
ProxyPassReverse /rep2/ibm http://reportingserver2.example.com/ibm

There is more information at the apache documentation site for mod_proxy.

If you need to change the links in the content returned from the external sites, you can do that using mod_ext_filter. Here's a sample configuration to rewrite a link:

# mod_ext_filter directive to define a filter which
# replaces text in the response
#
# Note: I'm Using a '#' instead of an '/' in the sed command since I want to
# include '/' in the string
#
ExtFilterDefine rep1 mode=output intype=text/html \
    cmd="/bin/sed s#reportingserver1.example.com/ibm#example.com/rep1/ibm#g"

<Location /rep1>
    # core directive to cause the fixtext filter to
    # be run on output
    SetOutputFilter rep1
    ProxyPass /rep1/ibm http://reportingserver1.example.com/ibm
    ProxyPassReverse /rep1/ibm http://reportingserver1.example.com/ibm
</Location>
4
  • That would indeed forward me to the correct one for the login. But once inside that external portal If I click there, will it still have that rep1 or rep2 prefix so that Apache can sent the request to the correct server?
    – gotjee
    Mar 21, 2014 at 11:41
  • That may depend on how the links are written on that server. I'll add information about how to rewrite them if necessary, give me a few miuntes...
    – Jenny D
    Mar 21, 2014 at 11:45
  • @gotjee Edit finished, hope it works for you.
    – Jenny D
    Mar 21, 2014 at 11:57
  • thanks for your extensive answer, I'm using this on Windows server so the part with the sed command etc will be a bit different, but I will be testing this more this week & will read up on that mod_ext_filter, thanks for pointing me in that direction.
    – gotjee
    Mar 24, 2014 at 9:54
0

I am able to do it now using the combination of mod_proxy for reverse proxy and mod_proxy_html with ProxyHTMLURLMap for rewriting the returned content. The initial page loads OK & all URL etc are rewritten, they show the rep1 prefix when I hoover over them.

But when I click one of the menu's in the proxied application, I think an Ajax request is being done & the returned page will be inserted. But I'm facing an issue where the returned content is being surrounded with "<html><body>" tags. and because of this the page isn't updating I think.

I'm trying to figure out how I could stop proxy_html from doing this.

My current configuration:

ProxyPass /MD/ http://xx.xxx.xxx.xx:8080/

<Location /MD/>
    ProxyHTMLURLMap /ibm/ /MD/ibm/ 
    ProxyHTMLURLMap /mum/ /MD/mum/ 
    ProxyPassReverse /
    RequestHeader unset Accept-Encoding
    ProxyHTMLEnable On
    #ProxyHTMLInterp On
    ProxyHTMLEvents On
    ProxyHTMLExtended On

        #SetOutputFilter DEFLATE
        #SetOutputFilter INFLATE;proxy-html;DEFLATE
        #SetOutputFilter INFLATE;proxy-html;SUBSTITUTE;DEFLATE
        #SetOutputFilter proxy-html
        #ProxyHTMLBufSize 6000000
        #ProxyHTMLMeta On

    ProxyHTMLLinks  a               href
    ProxyHTMLLinks  area            href
    ProxyHTMLLinks  link            href
    ProxyHTMLLinks  img             src longdesc usemap
    ProxyHTMLLinks  object          classid codebase data usemap
    ProxyHTMLLinks  q               cite
    ProxyHTMLLinks  blockquote      cite
    ProxyHTMLLinks  ins             cite
    ProxyHTMLLinks  del             cite
    ProxyHTMLLinks  form            action
    ProxyHTMLLinks  input           src usemap
    ProxyHTMLLinks  head            profile
    ProxyHTMLLinks  base            href
    ProxyHTMLLinks  script          src for
    ProxyHTMLLinks  frame           src longdesc
    ProxyHTMLLinks  iframe          src longdesc
    ProxyHTMLLinks  body            background
    ProxyHTMLLinks  applet          codebase

    ProxyHTMLCharsetOut *
    ProxyHTMLEvents onclick ondblclick onmousedown onmouseup onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup onfocus onblur onload onunload onsubmit onreset onselect onchange  
</Location>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .