HAProxy community

Combination of path_beg and hdr not working


#1

Hi,

I am trying to send requests to api.mydomain.com/some-service to another backend serving the actual some-service.
Since I’m hosting many different domains in haproxy, I need to make sure requests going to some-service arehaving api.mydomain.com on host header not anything else.

here is a sample of my configuration

frontend server
    bind *:443 ssl crt /etc/haproxy/ssl/cent.pem
    acl API hdr(Host) -i api.mydomain.com
    acl SERVICE path_beg -i /some-service 
    use_backend back_service if SERVICE API
    use_backend back_api if API 

backend back_service
  option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    server service 172.16.1.62:80 check maxconn 1000

backend back_api
  option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    server api 172.16.1.60:80 check maxconn 1000

the result with this config is all requests are going to bach_api.


#2

try this, since you strictly want SERVICE acl to go back_service, added a negation flag to ignore SERVICE path

 use_backend back_service if SERVICE API 
 use_backend back_api if !SERVICE API

#3

Also I think you can change the order of the lines. Try this :

use_backend back_api if API
use_backend back_service if SERVICE API