There seems to be some problems when trying to proxy "/" with
ProxyPass and mod_proxy_balancer.

See also:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51982
https://issues.apache.org/bugzilla/show_bug.cgi?id=51489

I could reproduce both errors in httpd-2.4.3:
  1) error 500 when configuring "ProxyPass / balancer://default"
  2) double-slash problem when backend returns 301



Sample config:
########################################
ProxyPreserveHost Off
<Proxy balancer://default>
    BalancerMember http://backend1.foo:5080 route=0
    BalancerMember http://backend2.foo:5080 route=1
    ProxySet lbmethod=bybusyness nofailover=off 
stickysession=JSESSIONID|jsessionid
</Proxy>

ProxyPass / balancer://default
ProxyPassReverse / balancer://default
########################################


1)
When configuring "ProxyPass / balancer://default", an error 500
occurs. When using a different ProxyPassMatch config, everything
works fine, e.g.: ProxyPassMatch ^/(.*)$ balancer://default/$1

I broke it down to mod_proxy.c::ap_proxy_trans_match().
"r->filename" resp. "found" is set to "proxy:balancer://defaultclusterjsp"
when for e.g. the URL "http://mydomain.foo/clusterjsp"; is called.
"r->filename" should be "proxy:balancer://default/clusterjsp".

I wrote a patch for httpd-2.4.3 (attached) - maybe someone can
review and improve it to get it finally in trunk.


2)
When the patch from 1) is applied, you will run into another problem.
On 301 from backend, an dispensable "/" will be prepended to the URI.
E.g. when you call http://mydomain.foo:8080/clusterjsp in you browser, the
redirect location will be set wrong:
Location: http://mydomain.foo:8080//clusterjsp/

This will result in session problems... (cookie path is "/clusterjsp" and
not "//clusterjsp").

See attached logfile for more details.

A patch was proposed in https://issues.apache.org/bugzilla/show_bug.cgi?id=51489
for httpd-2.4.x, which is working for me.

I did a quick check with:
u = apr_pstrcat(r->pool, (strcmp(ent[i].fake, "/") == 0 ? "" : ent[i].fake), 
&url[l2], NULL);




regards,
zisis

[Wed Sep 05 18:46:03.780655 2012] [core:trace5] [pid 16732:tid 140666604746496] 
protocol.c(627): [client 10.x.x.x:53812] Request received from client: GET 
/clusterjsp HTTP/1.0
[Wed Sep 05 18:46:03.780880 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(301): [client 10.x.x.x:53812] Headers received from client:
[Wed Sep 05 18:46:03.780904 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Host: mydomain.foo:8080
[Wed Sep 05 18:46:03.780918 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   User-Agent: Mozilla/5.0 (X11; 
Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0
[Wed Sep 05 18:46:03.780933 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Accept: 
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[Wed Sep 05 18:46:03.780945 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Accept-Language: en-us,en;q=0.5
[Wed Sep 05 18:46:03.780957 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Accept-Encoding: gzip, deflate
[Wed Sep 05 18:46:03.780969 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Cookie: 
JSESSIONID=74ed1ff134626b3d85e4ec2ebca9.0; 
__utma=85701643.1776763863.1324649383.1324649383.1324649383.1
[Wed Sep 05 18:46:03.780981 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Via: 1.0 
proxyserver.mydomain:3128 (squid/2.7.STABLE5)
[Wed Sep 05 18:46:03.780992 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   X-Forwarded-For: 10.x.x.x
[Wed Sep 05 18:46:03.781003 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Cache-Control: max-age=259200
[Wed Sep 05 18:46:03.781023 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.x.x.x:53812]   Connection: keep-alive
...
[Wed Sep 05 18:46:03.781220 2012] [proxy_balancer:trace1] [pid 16732:tid 
140666604746496] mod_proxy_balancer.c(73): [client 10.x.x.x:53812] 
canonicalising URL //default/clusterjsp
[Wed Sep 05 18:46:03.781300 2012] [proxy_balancer:debug] [pid 16732:tid 
140666604746496] mod_proxy_balancer.c(292): [client 10.x.x.x:53812] AH01160: 
Found value 74ed1ff134626b3d85e4ec2ebca9.0 for stickysession JSESSIONID
[Wed Sep 05 18:46:03.781319 2012] [proxy_balancer:debug] [pid 16732:tid 
140666604746496] mod_proxy_balancer.c(302): [client 10.x.x.x:53812] AH01161: 
Found route 0
[Wed Sep 05 18:46:03.781338 2012] [proxy_balancer:debug] [pid 16732:tid 
140666604746496] mod_proxy_balancer.c(614): [client 10.x.x.x:53812] AH01172: 
balancer://default: worker (http://backend1.foo:5080) rewritten to 
http://backend1.foo:5080/clusterjsp
[Wed Sep 05 18:46:03.781353 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(1656): AH00924: worker http://backend1.foo:5080 shared already 
initialized
[Wed Sep 05 18:46:03.781367 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(1700): AH00927: initializing worker http://backend1.foo:5080 local
[Wed Sep 05 18:46:03.781403 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(1732): AH00930: initialized pool in child 16732 for (backend1.foo) 
min=0 max=50 smax=50
[Wed Sep 05 18:46:03.781422 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
mod_proxy.c(1071): [client 10.x.x.x:53812] AH01143: Running scheme balancer 
handler (attempt 0)
[Wed Sep 05 18:46:03.781446 2012] [proxy_http:trace1] [pid 16732:tid 
140666604746496] mod_proxy_http.c(2183): [client 10.x.x.x:53812] HTTP: serving 
URL http://backend1.foo:5080/clusterjsp
[Wed Sep 05 18:46:03.781473 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(1981): AH00942: HTTP: has acquired connection for (backend1.foo)
[Wed Sep 05 18:46:03.781505 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(2033): [client 10.x.x.x:53812] AH00944: connecting 
http://backend1.foo:5080/clusterjsp to backend1.foo:5080
[Wed Sep 05 18:46:03.783460 2012] [proxy:debug] [pid 16732:tid 140666604746496] 
proxy_util.c(2155): [client 10.x.x.x:53812] AH00947: connected /clusterjsp to 
backend1.foo:5080
...
[Wed Sep 05 18:46:03.794780 2012] [proxy_http:trace3] [pid 16732:tid 
140666604746496] mod_proxy_http.c(1689): [client 10.x.x.x:53812] Status from 
backend: 301
[Wed Sep 05 18:46:03.794842 2012] [proxy_http:trace4] [pid 16732:tid 
140666604746496] mod_proxy_http.c(1373): [client 10.x.x.x:53812] Headers 
received from backend:
[Wed Sep 05 18:46:03.794880 2012] [proxy_http:trace4] [pid 16732:tid 
140666604746496] mod_proxy_http.c(1375): [client 10.x.x.x:53812] Location: 
http://backend1.foo:5080/clusterjsp/
...
[Wed Sep 05 18:46:03.795346 2012] [http:trace3] [pid 16732:tid 140666604746496] 
http_filters.c(963): [client 10.x.x.x:53812] Response sent with status 301, 
headers:
[Wed Sep 05 18:46:03.795373 2012] [http:trace5] [pid 16732:tid 140666604746496] 
http_filters.c(970): [client 10.x.x.x:53812]   Date: Wed, 05 Sep 2012 16:46:03 
GMT
[Wed Sep 05 18:46:03.795392 2012] [http:trace5] [pid 16732:tid 140666604746496] 
http_filters.c(973): [client 10.x.x.x:53812]   Server: Apache/2.4.3 (Unix) 
OpenSSL/1.0.1c
[Wed Sep 05 18:46:03.795421 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_filters.c(806): [client 10.x.x.x:53812]   Location: 
http://mydomain.foo:8080//clusterjsp/
...
[Wed Sep 05 18:46:03.871640 2012] [core:trace5] [pid 16732:tid 140666604746496] 
protocol.c(627): [client 10.x.x.x:53812] Request received from client: GET 
//clusterjsp/ HTTP/1.0
[Wed Sep 05 18:46:03.871799 2012] [http:trace4] [pid 16732:tid 140666604746496] 
http_request.c(305): [client 10.17.0.5:53812]   Cookie: 
__utma=85701643.1776763863.1324649383.1324649383.1324649383.1

==> no JSESSIONID cookie is sent to server because of "/clusterjsp" != 
"//clusterjsp".




--- httpd-2.4.3/modules/proxy/mod_proxy.c	2012-07-23 14:16:10.000000000 +0200
+++ httpd-2.4.3/modules/proxy/mod_proxy.c	2012-09-05 16:44:10.875528769 +0200
@@ -624,7 +624,7 @@
                 mismatch = 1;
                 use_uri = r->uri;
             }
-            found = apr_pstrcat(r->pool, "proxy:", real, use_uri + len, NULL);
+            found = apr_pstrcat(r->pool, "proxy:", real, ((len == 1) ? use_uri : use_uri + len), NULL);
         }
     }
     if (mismatch) {

Reply via email to