Reqrep working globally when specified in backend

Hi,
I’m new to the forum, so sorry if I broke any rules ;).
I’m doing a simulated environment on my VM. I’m using docker swarm to run nginx instances and then consul with consul template to populate haproxy.cfg file in order to create a reverse proxy. (Which is actually irrelevant to the question). I’m generating the following config file: (I’ve cut out not important parts)

frontend http-in

bind *:80
acl app4 path_beg -i /nginx1
acl app5 path_beg -i /nginx10
use_backend srvs_app4 if app4
use_backend srvs_app5 if app5

backend srvs_app4
mode http
balance roundrobin
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
reqrep ^([^\ ]\ /)nginx1[/]?(.) \1\2
server host0 192.168.56.131:10001 check

backend srvs_app5
mode http
balance roundrobin
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
reqrep ^([^\ ]\ /)nginx10[/]?(.) \1\2
server host0 192.168.56.130:10010 check

As I imagine it should work is that when I connect to 192.168.56.130/nginx1 I should connect to 192.168.56.131:10001, and have my requests cut out the “nginx1” part. If I connect to to 192.168.56.130/nginx10 I should connect to 192.168.56.130:10010 and cut out the “nginx10” part. Issue is that when I have the nginx1 container running (thus the nginx1 part in config file) the nginx10 is returning me the 404 error from nginx. When I turn the container off (and the consul template removes the nginx1 related part from config) it works ok.

I think the issue is that the reqrep rule from backend related to nginx1 is actually cutting the nginx1 part from the backend related to nginx10 before it gets to it, leaving the 0 behind (or any other digit for that matter). I’ve tried it with higher numbers (nginx2 and nginx20 to 29, nginx3 and nginx30 - 39) and it behaves the same. I also tried to add “if app{{number}}” statement after the reqrep but then its not redirecting traffic at all.

Hope I made myself clear enough to understand :). Any idea how to fix the behaviour?

I’ve implemented workaround with adding 0’s before the number and its working ok, still don’t think it is intedned behaviour.