Apache – Configuring Reverse Proxy Routes with Similar URLs

apache-2.4reverse-proxy

I have this simple reverse proxy setup in my docker container(apache) each mapped to a different microservice with two different docker containers.

#serviceOne 
ProxyPass /abc/xyz/ http://serviceOne:8080/abc/xyz/ Keepalive=On
ProxyPassReverse /abc/xyz/ http://serviceOne:8080/abc/xyz/


#servicetwo 
ProxyPass /abc/xyz/pqr/ http://servicetwo:8080/abc/xyz/pqr/ Keepalive=On
ProxyPassReverse /abc/xyz/pqr/ http://servicetwo:8080/abc/xyz/pqr/

With this in place, I am not able to reach any relative route in the second service such as /abc/xyz/pqr/testprocess is not reachable, while it works properly when only single reverse proxy route is kept.

Best Answer

This was quite obvious and I actually could get it while framing this question :)

in such cases, what matters is the order in which these mappings are placed.

#servicetwo 
ProxyPass /abc/xyz/pqr/ http://servicetwo:8080/abc/xyz/pqr/ Keepalive=On
ProxyPassReverse /abc/xyz/pqr/ http://servicetwo:8080/abc/xyz/pqr/

#serviceOne 
ProxyPass /abc/xyz/ http://serviceOne:8080/abc/xyz/ Keepalive=On
ProxyPassReverse /abc/xyz/ http://serviceOne:8080/abc/xyz/

Just changing the order of these two mappings resolved the issue.

Although this was quite obvious, I could not find anything about reverse proxy URL order in apache documentation.

Even google could not return any solution or might be I could not frame the question properly.

If others could add more technical explanation to this answer, It will be great.

EDIT: There is a clear note about this in the documentation at https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#:~:text=ordering%20or%20override.-,Ordering%20ProxyPass%20Directives,URL.%20Note%20that%20there%20is%20some%20relation%20with%20worker%20sharing,-.