问题
is there a way to redirect to a specific backend, based on the path?
Goal: http://example.com/node1 --> use backend myserver:8080
http://example.com/node2 --> use backend myserver:8081
http://example.com/node3 --> use backend myserver:8082
http://example.com/ --> use backend myserver:8080, 8081, 8082
This is my configuration:
frontend
...
acl head_domain hdr_beg(host) -i example.com
acl head_n1 path_beg -i /node1
acl head_n1_ref hdr_dir(Referer) -i /node1
use_backend be_n1 if head_n1_ref head_domain
use_backend be_n1 if head_n1 head_domain
use_backend sall if head_domain !head_n1_ref !head_n1
...same for other nodes
backend sall
balance leastconn
mode http
option forwardfor
stick-table type ip size 200k expire 1h
stick on src
#default-server inter 2s
server s_1 myserver:8080 check
server s_2 myserver:8081 check
server s_3 myserver:8082 check
backend be_n1
mode http
reqirep ^([^\ :]*)\ /node1(.*) \1\ /\2
server s_n1 myserver:8080
backend be_n2
mode http
reqirep ^([^\ :]*)\ /node2(.*) \1\ /\2
server s_n2 myserver:8081
...
This works partly. I can enter example.com/node1 and I'm being redirected to node1 on "/". But as soon as I click somehwere, I'm going via "backend sall" since all links on the page don't have the "/node1" in it. How can I rewrite the urls on the page, so that all will have a /node1/ in it, when I'm going via /node1 ? The haproxy should remove this /node1/ again, which is already happening on the backend config. But the response also has all /node1 removed, so all further clicks will go via the sall backend :/
来源:https://stackoverflow.com/questions/48906648/haproxy-backend-redirect-based-on-path