HAproxy – SSL and virtual hosts issues

Apache2clusterhaproxy

HAProxy Config:

frontend https-proxy
      bind *:443 ssl crt /path/to/certs
      default_backend web

backend web
      balance roundrobin
      option httpchk
      option forwardfor
      option httpclose

      server web-srv1 192.168.1.1:80 check inter 5000
      server web-srv2 192.168.1.2:80 check inter 5000

Apache Conf:

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

<VirtualHost *:443>
    ServerName test.example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

Shared IP – 192.168.1.3

example.com goes to 192.168.1.3

test.example.com goes to 192.168.1.1

Going to test.example.com and bypassing the proxy, the virtual host works just fine.

Going through the proxy at example.com, for some reason it goes to the default instance in the conf files. (The SSL.conf file is included in the apache conf as well)

Not sure why this is occurring, maybe it's an apache configuration.

Best Answer

Because your backends point to 192.168.1.1:80 and 192.168.1.2:80 , however your Apache vhost is configured to listen on port 443 instead of port 80.