HAProxy reqrep remove URI on backend request

Posted by Jim on Server Fault See other posts from Server Fault or by Jim
Published on 2012-11-02T23:20:14Z Indexed on 2012/11/03 17:06 UTC
Read the original article Hit count: 4509

Filed under:
|
|
|

real quick question regarding HAProxy reqrep. I am trying to rewrite/replace the request that gets sent to the backend.

I have the following example domain and URIs

http://domain/web1
http://domain/web2

I want web1 to go to backend webfarm1, and web2 to go to webfarm2. Currently this does happen. However I want to strip off the web1 or web2 URI when the request is sent to the backend.

Here is my haproxy.cfg

frontend webVIP_80
        mode http
        bind    :80
        #acl routing to backend
        acl web1_path path_beg /web1
        acl web2_path path_beg /web2

        #which backend
        use_backend webfarm1 if web1_path
        use_backend webfarm2 if web2_path
        default_backend webfarm1

backend webfarm1
        mode http
        reqrep ^([^\ ]*)\ /web1/(.*)     \1\ /\2
        balance roundrobin
        option httpchk HEAD /index HTTP/1.1\r\nHost:\ example.com
        server webtest1 10.0.0.10:80 weight 5 check slowstart 5000ms
        server webtest2 10.0.0.20:80 weight 5 check slowstart 5000ms
backend webfarm2
        mode http
        reqrep ^([^\ ]*)\ /web2/(.*)     \1\ /\2
        balance roundrobin
        option httpchk HEAD /index HTTP/1.1\r\nHost:\ example.com
        server webtest1-farm2 10.0.0.110:80 weight 5 check slowstart 5000ms
        server webtest2-farm2 10.0.0.120:80 weight 5 check slowstart 5000ms

If I go to http://domain/web1 or http://domain/web2 I see it in the error logs that the request on a server in each backend that the requst is for the resource /web1 or /web2 respectively. Therefore I believe there to be something wrong with my regular expression, even though I copied and pasted it from the Documentation. http://code.google.com/p/haproxy-docs/wiki/reqrep

Summary: I'm trying to route traffic based on URI, however I want to strip the URI on the backend side.

Go to http://domain/web1 --> backend request of / to webfarm1

Thank you!

-Jim

© Server Fault or respective owner

Related posts about load-balancing

Related posts about rewrite