kettek2/wiki/articles/haproxy-transparent-proxy.qwk

70 lines
1.7 KiB
Plaintext

Got one server with multiple HTTP services?
Want a scheme like:
myhost.net/
-> 127.0.0.1:8080
myhost.net/app1
-> 127.0.0.1:8081
myhost.net/app2
-> 127.0.0.1:8082
OKAY!
Assuming haproxy.cfg's global and defaults sections to be stock:
frontend http-in
bind *:80
# our hosts
acl match_default path_beg /
acl match_app1 path_beg /app1
acl match_app2 path_beg /app2
## map our hosts to the appropriate backends
use_backend host_app1 if match_app1
use_backend host_app2 if match_app2
use_backend host_default if match_default
backend host_default
server node0 127.0.0.1:8080
backend host_app1
server node0 127.0.0.1:8081
reqrep ^([^\ ]*\ /)app1[/]?(.*) \1\2
backend host_app2
server node0 127.0.0.1:8082
reqrep ^([^\ ]*\ /)app2[/]?(.*) \1\2
There ya go!
How about a scheme like:
request for *
-> 10.0.0.1:8081
request for app1.net
-> 10.0.0.2:80
request for app2.net
-> 10.0.0.3:80
Try this!
frontend http-in
bind *:80
# our hosts
acl match_app1 hdr(host) -i app1.net
acl match_app2 hdr(host) -i app2.net
## map our hosts to the appropriate backends
use_backend host_default
use_backend host_app1 if match_app1
use_backend host_app2 if match_app2
backend host_default
server node0 10.0.0.1:8081
backend host_app1
server node0 10.0.0.2:80
backend host_app2
server node0 10.0.0.3:80