Basically, what the title says. I’d like to use a map file to simplify the haproxy configuration file. Currently the frontend and backend sections of the configuration file look like this:
frontend http
maxconn 2000
bind 0.0.0.0:5000
acl test_service-webserver path_reg -i /service/test_service/.*
use_backend servers-test_service-webserver if test_service-webserver
acl test_service-rest path_reg -i /service/rest/test_service/.*
use_backend servers-test_service-rest if test_service-rest
backend servers-test_service-webserver
balance leastconn
cookie TESTNAME insert
http-request set-header X-Forwarded-Proto https if { ssl_fc }
server servername1.intranet.com 127.0.0.1:9000 cookie S1 check inter 30s fall 1 rise 1
backend servers-test_service-rest
balance leastconn
cookie TESTNAME insert
reqrep ^(.+)\ /service/rest/test_service/(.*?$) \1\ /\2
server servername1.intranet.com 127.0.0.1:9001 cookie S1 check inter 30s fall 1 rise 1
This is the basic syntax, though in the real case, the configuration has several dozen acl with corresponding backends, making maintenance somewhat painful.
My idea is to extract the ACLs into a separate map file, meaning that instead of having several hundred ACLs, the configuration file will have one line that will check for the required path in the map file, and then look for the related backend name to route to:
haproxy.cfg:
frontend http
maxconn 2000
bind 0.0.0.0:5000
use_backend bk_%[base,map_beg(/apps/haproxy/config/haproxy.map)]
backend servers-test_service-webserver
balance leastconn
cookie TESTNAME insert
http-request set-header X-Forwarded-Proto https if { ssl_fc }
server servername1.intranet.com 127.0.0.1:9000 cookie S1 check inter 30s fall 1 rise 1
backend servers-test_service-rest
balance leastconn
cookie TESTNAME insert
reqrep ^(.+)\ /service/rest/test_service/(.*?$) \1\ /\2
server servername1.intranet.com 127.0.0.1:9001 cookie S1 check inter 30s fall 1 rise 1
haproxy.map:
http://servername1.intranet.com:5000/service/test_service/ servers-platformbot_faq-webserver
http://servername1.intranet.com:5000/service/rest/test_service/ servers-platformbot_faq-rasaserver
So far, I have not been able to make this work, receiving only 503 errors when going to the http://servername1.intranet.com:5000/service/test_service/home, when it should map to the webserver backend. Is what I’m trying to do possible with HAProxy 1.5? If not are there any other workarounds? I realize that 1.5 is EOL, but I am limited to it due to my organization not upgrading.