G
G
Gring762015-09-27 12:06:03
Debian
Gring76, 2015-09-27 12:06:03

How to work with subdomains in haproxy?

Good day to all :-)
There is a machine with virtualization, several virtual machines with web services.
In order to save ipv4, I decided to use haproxy.
Everything worked fine, for the time being, I didn’t need to fasten 1 more virtual machine.
And then the problems began.
Haproxy is redirecting to the wrong VM.
Here is my config

frontend http_frontend
bind 1xx.yy.zzz.138:80
mode http
option httpclose
acl is_mytest1 hdr_end(host) -i test.mysite.com
use_backend mytest1_web if is_mytest1
acl is_mytest2 hdr_end(host) -i test2.mysite.com
use_backend mytest2_web if is_mytest2
acl is_mytest3 hdr_end(host) -i mysite.com
use_backend mytest3_web if is_mytest3
acl is_mytest3 hdr_end(host) -i www.mysite.com
use_backend mytest3_web if is_mytest3
acl is_mytest4 hdr_end(host) -i test4.mysite.com
use_backend mytest4_web if is_mytest4


backend mytest1_web
mode http
cookie SERVERID insert indirect nocache
server mytestweb1 192.168.200.102:80 check cookie mytestweb1

backend mytest2_web
mode http
cookie SERVERID insert indirect nocache
server mytestweb2 192.168.200.101:80 check cookie mytestweb2

backend mytest3_web
mode http
cookie SERVERID insert indirect nocache
server mytestweb3 1xx.yy.xxx.189:80 check cookie mytestweb3

backend mytest4_web
mode http
cookie SERVERID insert indirect nocache
server mytestweb4 192.168.200.104:80 check cookie mytestweb4

For some reason, when test4.mysite.com is requested, mysite.com opens for some
reason
All other sites test1.mysite.com test2.mysite.com www.mysite.com mysite.com open as
planned main domain mysite.com Tell me
which way to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gring76, 2015-09-27
@Gring76

If you remove the lines about the 2nd level domain from the config, then everything works as it should

acl is_mytest1 hdr_end(host) -i test.mysite.com
use_backend mytest1_web if is_mytest1
acl is_mytest2 hdr_end(host) -i test2.mysite.com
use_backend mytest2_web if is_mytest2
# acl is_mytest3 hdr_end(host) -i mysite.com
# use_backend mytest3_web if is_mytest3
acl is_mytest3 hdr_end(host) -i www.mysite.com
use_backend mytest3_web if is_mytest3
acl is_mytest4 hdr_end(host) -i test4.mysite.com
use_backend mytest4_web if is_mytest4

But at the same time, the domain without the www prefix does not open
. It seems like I found a solution.
acl is_mytest1 hdr(host) -i test.mysite.com
use_backend mytest1_web if is_mytest1
acl is_mytest2 hdr(host) -i test2.mysite.com
use_backend mytest2_web if is_mytest2
acl is_mytest3 hdr(host) -i mysite.com
use_backend mytest3_web if is_mytest3
acl is_mytest3 hdr(host) -i www.mysite.com
use_backend mytest3_web if is_mytest3
acl is_mytest4 hdr(host) -i test4.mysite.com
use_backend mytest4_web if is_mytest4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question