ProxyPass
by itself enables the reverse proxy functionality and in some cases that is enough. For example ProxyPass / http://localhost:8080/
configures Apache to proxy the site from a back end server.
This works pretty well until the back end wants to issue redirects. Redirects have to be to fully qualified absolute URLs. To redirect /foo
to /bar
the back end would respond with a redirect response with Location: http://localhost:8080/bar
. If that got proxied directly to the client, the redirect would break.
One solution to this problem would be to reconfigure the back end to know that it is serving http://mysite.example
and not http://localhost:8080
. Then it could use the correct absolute redirects. This could even be done dynamically by having the back end examine X-Forwarded-For
headers that tell it when it is behind a reverse proxy or send the Host:
header to the backend with ProxyPreserveHost.
However, not all back ends support such configuration. If not you can use the ProxyPassReverse directive to change the Location
header on the response. That configuration only exists to fix broken redirects from the back end.
Similarly ProxyPassReverseCookieDomain is meant to fix when the back end tries to set cookies for the wrong domain. You can even install mod_proxy_html to parse all the HTML from the back end and fix any absolute links within the HTML documents.