Bug 51982 - ProxyPassReverse / balancer://cluster/ adds slash to redirect (really!)
Summary: ProxyPassReverse / balancer://cluster/ adds slash to redirect (really!)
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy (show other bugs)
Version: 2.2.21
Hardware: All Linux
: P2 normal with 2 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Depends on:
Reported: 2011-10-06 19:56 UTC by Luke Meyer
Modified: 2014-03-26 12:49 UTC (History)
2 users (show)

httpd-2.2 backport of proxy doubleslash fixes r1386576, r1386578 (900 bytes, patch)
2013-04-11 16:31 UTC, William A. Rowe Jr.
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Meyer 2011-10-06 19:56:21 UTC
This report appears similar to some others, like 39203 and particularly 51489. But I believe the following configuration demonstrates a specific problem simply and is in fact a bug - feel free to prove me wrong:

<Proxy balancer://cluster >
BalancerMember http://localhost:8080

ProxyPass / balancer://cluster/
# option 1
ProxyPassReverse / http://localhost:8080/
# option 2
ProxyPassReverse / balancer://cluster/

Option 1 and 2 should both correctly rewrite Location: headers from the backend. Option 1 does, but option 2 adds an extra / - so if the request was http://www.example.com/foo and the backend returns a Location: http://localhost:8080/foo/ then the rewritten result will be http://www.example.com//foo/ (with two slashes). Aside from looking/being incorrect, any cookies with path /foo (as is common with backend applications) won't match this path and thus the browser won't send them after the redirect.

Some things to note:
1. The behavior is no different with:
ProxyPassReverse / balancer://cluster
(i.e. without the trailing /)

2. This works fine if you do the following instead:
ProxyPass /foo balancer://cluster/foo
ProxyPassReverse /foo balancer://cluster
... however, the goal here is to proxy / (perhaps with exceptions) so there is no way to eliminate the trailing slashes.

3. You can try other combinations of adding/removing trailing slashes to your heart's content - I have not found one that both proxies to the correct backend location (without adding/removing a slash) and rewrites Location correctly. The only workaround is to ProxyPassReverse each of the individual BalancerMembers, which is what the balancer:// construct is intended to avoid.
Comment 1 sven.peters 2011-11-15 02:24:18 UTC
I ran into this problem too and didn't find a workaround yet.
My config

# Works perfect

ProxyPass / http://localhost:9381/
ProxyPassReverse / http://localhost:9381/

# Doesn't work when receiving Redirects / Location from the backend. An extra leading '/' is added.
# ProxyPass / balancer://balancer/
# ProxyPassReverse / balancer://balancer/

<Proxy balancer://balancer/>
        BalancerMember http://localhost:9381/ retry=1
        BalancerMember http://localhost:9382/ retry=1 status=D

Any workaround is appreciated.
Comment 2 Carlo Timmers 2012-04-20 21:39:00 UTC
This bug also exists in apache 2.2.12 and 2.2.22
Comment 3 Carlo Timmers 2012-04-20 21:54:20 UTC
(In reply to comment #2)
> This bug also exists in apache 2.2.12 and 2.2.22

Patch available in https://issues.apache.org/bugzilla/show_bug.cgi?id=51489 solved the issue for me.
Comment 4 sven.peters 2012-05-01 06:00:58 UTC
Does somebody have a patch for 2.2.22 for this?

The above patch seems to be for an older version and the logic seemed to have changed (I only checked .21 and .22).
Comment 5 Ajay Sindwani 2013-04-05 02:54:42 UTC
The workaround to this problem is to put multiple ProxyPassReverse directives, one for each balancer member

ProxyPass / balancer://balancer/
ProxyPassReverse / http://localhost:9381/
ProxyPassReverse / http://localhost:9382/

Does anybody know if this is fixed in a later version of Httpd?  If so which versions?
Comment 6 William A. Rowe Jr. 2013-04-11 16:31:12 UTC
Created attachment 30179 [details]
httpd-2.2 backport of proxy doubleslash fixes r1386576, r1386578

Folks, please test the attached backport before I submit it to STATUS.
Comment 7 Bong Samson 2013-04-11 20:47:37 UTC
William, your changes for the httpd-2.2 proxy double slash tested successfully. Thanks.
Comment 8 William A. Rowe Jr. 2013-04-12 19:36:11 UTC
Added to 2.2 STATUS for review.
Comment 9 William A. Rowe Jr. 2013-04-22 15:56:41 UTC
This is now committed for inclusion in a future 2.2.25
Comment 10 cweekly 2014-03-26 12:49:08 UTC
I don't think the backport was applied successfully in 2.2.26. That is, I believe this issue remains unresolved in 2.2.26. (I ran into it on 2.2.22, and found identical behavior in 2.2.26.) I ended up migrating to 2.4(.9) where it is in fact resolved.

I don't have time to recreate my 2.2.26 conf details here, but I can attest we saw this exact problem: extra slash introduced in Location header of redirect response from proxied apps, when proxying to a balancer (vs directly to a particular member -- which didn't meet our needs). 

Sorry for not having more rigorous details to reprod, but for anyone reading this experiencing frustration, may I heartily recommend biting the bullet and upgrading to 2.4. In the end our conf is cleaner and more concise, and mod_proxy_balancer + mod_rewrite are working in perfect harmony to route requests to one of multiple load-balanced apps behind a given apache. 

I'm reopening this to draw attention to it, but sorry in advance for not having time to discuss it much further.