Apache Proxy – Do ProxyPass Directives Need ProxyPassReverse?

apache-2.2mod-proxy

Do all ProxyPass Directives need a ProxyPassReverse Directive?

ProxyPass / http://foo.example.com:8080/  
ProxyPassReverse / http://www.example.com/

I saw this snippet, and understand that all traffic coming to foo.example.com is proxied to foo.example.com:8080. What does the second line do?

Best Answer

This directive lets Apache adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses.

For example, suppose the local server has address http://example.com/; then

ProxyPass /mirror/foo/ http://backend.example.com/
ProxyPassReverse /mirror/foo/ http://backend.example.com/
ProxyPassReverseCookieDomain backend.example.com public.example.com
ProxyPassReverseCookiePath / /mirror/foo/

will not only cause a local request for the http://example.com/mirror/foo/bar to be internally converted into a proxy request to http://backend.example.com/bar (the functionality ProxyPass provides here). It also takes care of redirects the server backend.example.com sends: when http://backend.example.com/bar is redirected by him to http://backend.example.com/quux Apache adjusts this to http://example.com/mirror/foo/quux before forwarding the HTTP redirect response to the client. Note that the hostname used for constructing the URL is chosen in respect to the setting of the UseCanonicalName directive.