HAproxy configuration

Hi,

I am facing problem to setup HAproxy when it is needed for different directories in URL to reach different backend systems. So, what is needed is when enter

www.evaplus.com/drs -> to access backend system

Setting I have is following:

acl host_www hdr_beg(host) -i www.evaplus.com
acl drs_hostname path_beg /drs
use_backend backend_drs if host_www drs_hostname
backend backend_drs
mode http
server backend_drs 172.16.2.59:8090

When I try to reach above url with ‘/drs’ , it is not possible.
What is wrong with this setting?

Thank you!
Miroslav

If i’m not mistaking acl’s are evaluated in order meaning host_www hdr_beg(host) -i www.evaplus.com will be evaluated before acl drs_hostname path_beg /drs.

A simple move of the two rules should solve your problem.

Kind regards,
Erland.

Thank you erland.

I am not sure that I understand how did you mean to move 2 rules.
I did it in following way:

acl drs_hostname path_beg /drs
acl host_www hdr_beg(host) -i www.evaplus.com
use_backend backend_drs if drs_hostname host_www
backend backend_drs
mode http
server backend_drs 172.16.2.59:8090

but still does not work. Still cannot reach www.evaplus.com/drs
If you meant differently, would you please give me right order I should put the rules.

Thank you!
Miroslav

Can you post your complete config please?

global
log 127.0.0.1 local0 debug
# log /var/log local0 info
chroot /var/lib/haproxy
# user haproxy
# group haproxy
maxconn 2000

defaults
log global
mode tcp
option tcplog
option dontlognull
timeout connect 500000
timeout client 500000
timeout server 500000

userlist hasler
group adm users admin
user admin insecure-password Hasler3018

WEB

##################################################################
frontend web
mode http
bind *:80
# Define ACL based on host names
acl c2c_hostname hdr(host) -i c2c.evaplus.com
acl multi_hostname hdr(host) -i haslerrail.evaplus.com
acl c2c_ip hdr(host) -i 52.214.141.171

    acl host_www hdr_beg(host) -i www.evaplus.com
    acl ussugar_hostname hdr(host) -i ussugar.evaplus.com
    acl adl_hostname hdr(host) -i adl.evaplus.com
    acl nor_hostname hdr(host) -i nor.evaplus.com
    acl int_hostname hdr(host) -i int.evaplus.com
    acl drs_hostname path_beg /drs
            
    # Default Route to normal backends
   
    use_backend backend_ussugar if ussugar_hostname
    use_backend backend_adl if adl_hostname
    use_backend backend_nor if nor_hostname
    use_backend backend_int if int_hostname
    use_backend backend_drs if drs_hostname host_www

default_backend backend_sales

backend backend_c2c
mode http
server backend_c2c 172.16.2.11:8180 check
server backend_test 172.16.1.63:8080 check backup

backend backend_ussugar
mode http
server backend_ussugar 172.16.2.59:8080

backend backend_adl
balance roundrobin
mode http
server backend_adl 172.16.2.59:8480 check
server backend_adl1 172.16.2.160:8480 check

backend backend_nor
mode http
server backend_nor 172.16.2.59:8580

backend backend_int
mode http
server backend_int 172.16.2.59:8180

backend backend_drs
mode http
server backend_drs 172.16.2.59:8090

Here it is, more or less.
The problem we are having is that , for each application in backed we would use different subdomain, like:

acl adl_hostname hdr(host) -i adl.evaplus.com
acl nor_hostname hdr(host) -i nor.evaplus.com
acl int_hostname hdr(host) -i int.evaplus.com

Now, we are running out of free subdomains in evaplus.com domain we reserved.
That is why we want to make routing where will not use subdomain for each backend we need to reach.

I understood from documentation that it should work with

acl drs_hostname path_beg /drs
acl host_www hdr_beg(host) -i www.evaplus.com
use_backend backend_drs if host_www drs_hostname

but, something is not ok.

Thank you!

Hi Miroslav,

I understand now.
Keep in mind that haproxy will proxy all incoming packets for <whatever_site>/drs to 172.16.2.59:8090/drs.
HAProxy will proxy, dut will not rewrite the url.

Erland.

Hi erland,

I expect when enter, in my case www.evaplus.com/drs HAproxy to reach 172.16.2.59:8090 - This is where my tomcat is running. (not 172.16.2.59:8090/drs). I also expect that condition,

use_backend backend_drs if host_www drs_hostname

will provide this.
Or do you have an idea what I should put differently in order proxy to reach only 172.16.2.59:8090 when someone enter www.evaplus.com/drs

Thank you!