6

The official document states that:

The ProxyPass configures the server to fetch the appropriate documents, while the ProxyPassReverse directive rewrites redirects originating at internal.example.com so that they target the appropriate directory on the local server.

From that I understand that ProxyPassReverse rewrites the header. But why do you need ProxyPass for? Why isn't ProxyPassReverse itself enough? What exactly does ProxyPass do?

3 Answers 3

4

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.

4

ProxyPass sends stuff to the origin server from the proxy. ProxyReversePass rewrites the Location: xxxx header in HTTP 3xx responses from the origin.

2

ProxyPass [path] [url]

[path]: It is often the http(s) request from your client. For example, if you want to proxy all requests that start with “/app” to (and from) a backend server, you would specify “/app” as the path.

[url]: The destination URL & port where the requests should be forwarded.

Note that both the [path] request and [url] destination URL & port act in a twofold way and ProxyPass directive has the "reverse" proxy functionality by default. This directive in some cases is more than enough like mentioned by Stephen above.

ProxyPassReverse

It is used to fix the the Location header on the response (“reverse” way) as it is proxied and different. Its parameters often repeat those of the ProxyPass directive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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