Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have setting up a series of web apps, which for security purposes are only directly accessible via localhost, with each service attached to a different port. To make these apps externally accessible, a reverse proxy is being setup through apache. It has been running smoothly until adding another app today, which is forwarding after initial access (I don't know by what method though, I do not have access to the code that is doing the redirecting) in a way such that "proxyHost/bar/" is redirecting to "proxyHost/search/" instead of "proxyHost/bar/search/"

I have looked over my script for setting up the proxy multiple times and have tried different approaches I have read about online and none are working for me. I now turn to you guys for help, I am very sorry if this is a rudimentary question or there is an obviously flaw in my config. I am quite new to apache.

Thanks!

Here is the current config:

 ProxyRequests Off
 ProxyPreserveHost On
 ProxyHTMLEnable On

 <Proxy *>
   Order allow,deny
   Allow from all
 </Proxy>

 ProxyPass /foo/ http://localhost:1234/
 ProxyHTMLURLMap http://localhost:1234 /foo

 <Location /foo/>
   ProxyPassReverse  http://localhost:1234/
   ProxyHTMLURLMap /          /foo/
   ProxyHTMLURLMap /foo      /foo
 </Location>

 ProxyPass /bar/ http://localhost:5678/search
 ProxyHTMLURLMap http://localhost:5678/ /bar

 <Location /bar/>
   ProxyPassReverse http://localhost:5678/
   ProxyHTMLURLMap /            /bar/
   ProxyHTMLURLMap /bar     /bar
 </Location>
share|improve this question

2 Answers 2

To restate your problem:

You've installed a new "backend" application and made it accessible under /bar on your frontend host. Access to the application results in a redirect to /search rather than /bar/search.

This generally happens because the backend application doesn't know anything about the frontend path under which you access it, and it generates absolute (vs. relative) URLs. There are a few ways of solving this problem:

  • Some applications let you configure a base URL that they will use when generating absolute links. This is the easiest solution if it's available; you would set the base URL to http://frontendhost/bar.
  • If you are unable to configure or modify the application, then you're going to need to filter the HTML it generates to rewrite links. This is (explicitly) what mod_proxy_html is for. Note that for Apache 2.4 and great, mod_proxy_html is [included][] as a standard module; for earlier versions of Apache you'll need to install it separately.

The mod_proxy_html documentation has some good examples.

share|improve this answer

Try something like:

ProxyPassReverse /bar/ http://backend.example.com/search/

as ProxyPassReverse is what does the header rewrites and your new app is slighty different on the backend as it's hosted under /search and not / like your previous setup

*edit Sorry I haven't used mod_proxy_html before but the same goes for your ProxyHTMLURLMap directives. The need to map from /search to /bar as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.