In Apache how to define multiple ProxyPass to different servers with the same context-root?
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>
Related videos on Youtube
gotjee
Updated on September 18, 2022Comments
-
gotjee almost 2 years
** 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.
-
Jenny D over 10 yearsYour two URL examples are identical. Could you double-check and verify them?
-
gotjee over 10 yearsIndeed my examples both had rep2 in URL, corrected to rep1 and rep2.
-
-
gotjee over 10 yearsThat 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?
-
Jenny D over 10 yearsThat 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 over 10 years@gotjee Edit finished, hope it works for you.
-
gotjee over 10 yearsthanks 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.