Haproxy with subdomains running on same port

Hi, we have configured multiple hosts(*.conf) in nginx running on same port on two boxes.

Box1: host1.bharathcloud.com web1.bharathcloud.com =>
Box2: host2.bharathcloud.com web2.bharathcloud.com =>


Same configuration is done of host2 and web2.

when accessing above url’s individually it’s displaying the required webpage. But when I try to configure it with haproxy to route to backends using host headers… for URL with web* its displaying webpage of host* and not the one corresponding to web*

Below is the haproxy configuration I have on both the boxes

frontend main
mode http
bind *:80
bind *:443 ssl crt /home/bcloud/certs/key.pem
use_backend web if { hdr(host) -i weblb.bharathcloud.com }
use_backend app if { hdr(host) -i hostlb.bharathcloud.com }
http-request redirect scheme https unless { ssl_fc }

backend web
balance roundrobin
server web1 web1.bharathcloud.com:8443 check ssl verify none
server web2 web2.bharathcloud.com:8443 check ssl verify none

backend app
balance roundrobin
server host1 host1.bharathcloud.com:8443 check ssl verify none
server host2 host2.bharathcloud.com:8443 check ssl verify none


Both weblb and hostlb are pointing to same VIP which has been configured using keepalived.

so when I try to access using weblb.bharathcloud.com instead of routing to web backend I am getting web page corresponding to app backend.

It works perfect when I try to configure host1/2 on different port and web1/2 on different port. But when I try to use same port for both its not working.

Request help on this.