How to redirect math only subdomains in HAProxy

Hello

I have following the docs at https://www.haproxy.com/documentation/aloha/9-0/traffic-management/lb-layer7/acls/. And try to setup subdomain and main domain but the request only use the backend domain in this case the backend gsviec. Here my config

acl host_gsviec  hdr_end(host) -i gsviec.com
acl host_note_gsviec  hdr_end(host) -i note.gsviec.com
|
|
use_backend note_gsviec if host_note_gsviec
use_backend gsviec if host_gsviec

backend gsviec
        balance leastconn
        cookie SERVERID insert indirect
        option httpclose
        option forwardfor
        server app 127.0.0.1:8000 cookie A check

backend host_note_gsviec
        balance leastconn
        option httpclose
        option forwardfor
        cookie JSESSIONID prefix
        server node1 127.0.0.1:7000 cookie A check
backend lackky

I have also change hdr_dom(host) but it did not work too
Anyone have same the problem?

You are configured to use a backend that you does not exists (note_gsviec != host_note_gsviec):

use_backend note_gsviec if host_note_gsviec
backend host_note_gsviec

Hi

I have just update, it’s do not work correct and I also restart haproxy too

Other than fixing the wrong backend reference you also need to fix the fetch to access the host header, which you already noticed in the first post.

So replace:

use_backend note_gsviec if host_note_gsviec

with

use_backend host_note_gsviec if host_note_gsviec

and replace:

acl host_gsviec  hdr_end(host) -i gsviec.com
acl host_note_gsviec  hdr_end(host) -i note.gsviec.com

with

acl host_gsviec  hdr_dom(host) -i gsviec.com
acl host_note_gsviec  hdr_dom(host) -i note.gsviec.com

Thanks you. It’s work now