URl path base routing with load balancing

I am new to HaProxy, i confirm the base base url in firsttime, i having 3 api’s in that 2 api’s working fine only one api’s getting 404 not found error.

I check that api is working fine and i use telnet command to check any blocking of network. it also look good. i am using haproxy:2.4v

you can find my haproxy.cfg file here.

global
	log /dev/log	local0
	log /dev/log	local1 notice
        log /var/log/haproxy/haproxy.log local2
#	chroot /var/lib/haproxy/
        ssl-default-bind-options ssl-min-ver TLSv1.2
	stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
	stats timeout 30s
	user haproxy
	group haproxy
	daemon


defaults
	log	global
	mode	http
	option	httplog
	option	dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
frontend http
        bind *:80
        bind *:443 ssl crt /etc/haproxy/certs/collector.xxxx.xxx.com.pem ssl-min-ver TLSv1.2
        mode http
        option forwardfor
        http-request set-header X-Forwarded-Proto https if { ssl_fc }
        http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
 
        acl PATH_collector path_beg -i /collector
        acl PATH_taskmetric path_beg -i /taskmetric
        acl PATH_nats path_beg -i /
        redirect scheme https if !{ ssl_fc }
    
        use_backend  collector  if PATH_collector
        use_backend  nats       if PATH_nats
        use_backend  taskmetric if PATH_taskmetric
        
backend collector
        mode http
        http-request add-header X-Forwarded-Proto https if { ssl_fc }
        server collector 10.x.x.x:8081 
backend nats
        mode http
        http-request add-header X-Forwarded-Proto https if { ssl_fc }
        server nats  10.x.x.x:8222   
#backend taskmetric
#        mode  http
#        server taskmetric 10.x.x.x:8082 
#        http-request replace-path /taskmetric(/)?(.*) /\2
#        option http-server-close
#        option forwardfor
#        http-request add-header X-Forwarded-Proto https if { ssl_fc }
#        http-request set-header X-Forwarded-Port %[dst_port]
#        http-request set-header X-Debug-Path %[path]
backend taskmetric
         mode http
         http-request add-header X-Forwarded-Proto https if { ssl_fc }
         http-request replace-path /taskmetric(/)?(.*) /\2
         server taskmetric 10.x.x.x:8082
         http-check send meth GET uri / 


All my api’s running as docker swarm.
thanks in advance

I guess you have an issue with your taskmetric backend. use_backend rules are evaluated following the declaration order. So collector backend can be selected as expected but then nats backend will always be used because all path begins with a slash. It is a kind of catch-all.

A solution is to remove the use-backend on nats with the corresponding ACL to use a default backend instead:

  acl PATH_collector path_beg -i /collector
  acl PATH_taskmetric path_beg -i /taskmetric
    
  use_backend  collector  if PATH_collector
  use_backend  taskmetric if PATH_taskmetric
  default_backend nats

Thanks, Capflam, it’s working fine. you save my time.