0

I currently am using haproxy to do reverse_proxy on my end.

Unfortunately, I cannot get it to work!.

This is my config:

backend twisted 
        mode http
        timeout connect 10s
        timeout server 30s
        balance roundrobin
        server apache1 127.0.0.1:11111 weight 1 maxconn 512

backend cometd
        mode http
        timeout connect 5s
        timeout server 5m
        balance roundrobin
        server cometd1 127.0.0.1:12345 weight 1 maxconn 10000

frontend http_proxy #arbitrary name for the frontend
        bind *:80 #all interfaces at port 80
        mode http
        option forwardfor
        option http-server-close
        option http-pretend-keepalive
        default_backend twisted #by default forward the requests to apache

        acl req_cometd_path path_beg /comet/
        use_backend cometd if req_cometd_path 

        acl req_cometd_host hdr_dom(host) -i comet.okiez.com
        use_backend cometd if req_cometd_host
  1. If I try to access localhost/comet/test1/test2, haproxy forwards to the cometd backend correctly. However, the request path remains to be /comet/test1/test2, where my comet engine (orbited) doesn't handle the /comet/ part. Is there anyway to tell haproxy to drop the first /comet/ in the requests that gets directed to the cometd backend?
  2. As you can see, I have acl req_cometd_host hdr_dom(host) -i comet.okiez.com too. This simply stopped working. I don't know if accessing http://comet.localhost/test1/test2 or comet.127.0.0.1/test1/test2 makes any sense at all. How can I write acl req_cometd_host hdr_dom(host) -i to for localhost addresses?
0

3 Answers 3

2

Put the

reqrep ^([^\ ]*)\ /comet/(.*) \1\ /\2

into your backend definition. That way, Haproxy can use that path for its routing decision in the frontend. Here, a request with /comet at the beginning will match the req_cometd_path acl and will thus be routed to the correct backend.

In the backend itself, you can now adjust the request to be suitable for the actual application server behind it. Thus the stated rule above is going to remove the /comet from the beginning of the path for all requests going through the comet backend.

Edited (added the following):

Regarding your second issue, hdr_dom only matches if the stated string (in your case comet.okiez.com) is found isolated or delimited by dots in the header. You probably want to use one of

# matches if 'comet' is somewhere in the host
acl req_cometd_host hdr_dom(host) -i comet
# matches if 'comet' is at the beginning the host
acl req_cometd_host hdr_beg(host) -i comet
# matches if the host is comet.okiez.com
acl req_cometd_host hdr(host) -i comet.okiez.com

For more details, have a look at the Haproxy configuration manual.

1
  • Thx, you actually forgot the * reqrep ^([^\ ]*)\ /comet/(.*) \1\ /\2
    – user57893
    Oct 22, 2010 at 20:01
0

Potential answer to question 1...

What your code is doing is declaring which backend to use but it isn't doing anything about redirection etc.

Maybe the following would help you...

acl req_cometd_path path_beg /comet/
redirect prefix /test1/test2/ if req_cometd_path
use_backend cometd if req_cometd_path

For the second question try the following instead -

acl req_cometd_host hdr_end(host) -i comet.okiez.com
use_backend cometd if req_cometd_host

Notice the hdr_end instead of hdr_dom.. Just a suggestion. I hope this helps!

0

You can use Request Replace to alter the URL on the fly.

HAProxy Docs

replace "/comet/" with "/" at the beginning of any request path.
reqrep ^([^\ ]*)\ /comet/(.*)     \1\ /\2

I'm not 100% sure about the order of operations. (acl operations vs use_backend)

However, I expect if you placed the reqrep line in your cometd backend code section it would be processed AFTER the acl.


Your host header check looks OK. How are you testing it? Do you have 'comet.okiez.com' in your /etc/hosts or in DNS resolving to 127.0.0.1?

You could also add the Host: header to a wget request.

eg.

wget --header="Host: comet.okiez.com" http://localhost/

You must log in to answer this question.