Bug 51489

Summary: ProxyPassReverse adds an additional slash in load balancer setups
Product: Apache httpd-2 Reporter: Micha Lenk <micha>
Component: mod_proxyAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED FIXED    
Severity: normal CC: nsg-apache-httpd-maintenance, sven.peters
Priority: P2    
Version: 2.4.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Fix additional slash added by ProxyPassReverse in LoadBalancer setup
Fix for Apache 2.4.2 (including fix for PR #45434)
Fix additional slash in load balancer setups

Description Micha Lenk 2011-07-08 16:16:23 UTC
Created attachment 27275 [details]
Fix additional slash added by ProxyPassReverse in LoadBalancer setup

When Apache is used as reverse proxy in a load balancer setup, the option 'ProxyPassReverse' adds an additional slash between the server name and the path in the Location: header sent to the web browser.

Used configuration (for reproduction of this issue):

<Proxy balancer://196f045aca6adc82a0b6eea93ed286a1>
	BalancerMember http://server-1.local status=-SE
	BalancerMember http://server-2.local status=-SE
</Proxy>
<VirtualHost 10.8.16.33:80>
	ServerName frontend.local

	<Location />
		ProxyPass balancer://196f045aca6adc82a0b6eea93ed286a1/
		ProxyPassReverse balancer://196f045aca6adc82a0b6eea93ed286a1/
	</Location>
</VirtualHost>

Apparently there is no way to alter the configuration to prevent the addition of the slash.
Comment 1 Micha Lenk 2011-08-22 13:15:23 UTC
I found out that I have no issue at all if the config consistently uses a slash after the load balancer id.

<Proxy balancer://196f045aca6adc82a0b6eea93ed286a1/>
    BalancerMember http://server-1.local/ status=-SE
    BalancerMember http://server-2.local/ status=-SE
</Proxy>
<VirtualHost 10.8.16.33:80>
    ServerName frontend.local

    <Location />
	ProxyPass balancer://196f045aca6adc82a0b6eea93ed286a1/
	ProxyPassReverse balancer://196f045aca6adc82a0b6eea93ed286a1/
    </Location>
</VirtualHost>

So, please consider the case as solved and the patch as void.
Comment 2 Micha Lenk 2011-10-17 16:50:01 UTC
No, consistently using a slash after the load balancer id does *not* help: In this case every backend request gets an additional slash before the path. Maybe we should fix *this* issue then...
Comment 3 William A. Rowe Jr. 2011-10-17 19:05:06 UTC
Please test

<Proxy balancer://196f045aca6adc82a0b6eea93ed286a1>
    BalancerMember http://server-1.local/ status=-SE
    BalancerMember http://server-2.local/ status=-SE
</Proxy>

Does this then result in doubled-slashes?
Comment 4 Micha Lenk 2011-10-18 08:51:55 UTC
yes
Comment 5 sven.peters 2012-05-01 05:47:53 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 6 Micha Lenk 2012-05-02 15:40:29 UTC
I can work on an updated patch (added to my TODO list), but I will need some
time for it due to a lot of other things keeping me busy at the moment...
Comment 7 Micha Lenk 2012-07-30 09:14:26 UTC
I just tried to reproduce the issue again with Apache 2.4.2. Now the directive
doesn't work at all in a load balancer setup. :(
Comment 8 Micha Lenk 2012-07-30 10:25:26 UTC
This tiny patch for Apache 2.4.2 makes the ProxyPassReverse work again in a load balancer setup, however, the initially reported bug with the additional slash is then still unfixed:

--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -852,6 +852,7 @@ PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r,
             (balancer = ap_proxy_get_balancer(r->pool, sconf, real, 1))) {
             int n, l3 = 0;
             proxy_worker **worker = (proxy_worker **)balancer->workers->elts;
+            real += strlen(BALANCER_PREFIX);
             const char *urlpart = ap_strchr_c(real, '/');
             if (urlpart) {
                 if (!urlpart[1])
Comment 9 Micha Lenk 2012-07-30 18:03:38 UTC
Ok, issue from last comment is already fixed in trunk via PR #45434.
Comment 10 Micha Lenk 2012-07-31 15:52:37 UTC
Created attachment 29145 [details]
Fix for Apache 2.4.2 (including fix for PR #45434)

Using gdb I just figured out what went wrong. Attached you can find my patch that made all things work for me using Apache 2.4.2.

I also tried to craft a test case for this issue, but for whatever reason the test harness does not fail (maybe related to the intense usage of non-default ports in the test setup).
Comment 11 Joe Orton 2012-08-17 13:56:18 UTC
Ah, I missed this bug before, sorry.  Yes, this is fixed for the next 2.4.x release, I'll update CHANGES to ref this bug since it's a different bug to the 2.2 issue, and a regression.
Comment 12 Micha Lenk 2012-08-17 14:51:17 UTC
I fear you got me wrong. The changeset you committed in SVN rev. 1374264 should be reverted, as the bug that got fixed in branch httpd-2.4.x by SVN rev. 1365604 is PR 45434 only. The issue that I reported in PR 51489 is *not* fixed by changing the CHANGES file only (as in SVN rev. 1374264).

Or did I miss anything?
Comment 13 Joe Orton 2012-08-17 14:53:57 UTC
Oh, I see.  Sorry, no, I missed the point.
Comment 14 Micha Lenk 2012-08-17 15:09:10 UTC
Created attachment 29248 [details]
Fix additional slash in load balancer setups

I've just rewritten the patch to catch the problem more precisely.
Comment 15 Micha Lenk 2012-08-17 15:10:11 UTC
The patch from previous comment is based on branch httpd-2.4.x, SVN rev. 1374290.