I've setup Haproxy, varnish and apache2 on ubuntu server and there are multiple web site running with http and https.
following setup configured as below:
---443--> |
| HAProxy ------>Varnish(8081) ----------> apache2(8080)
---80---> |
haproxy.cfg
frontend http-example
bind *:80
frontend https-example
bind *:443 ssl crt /etc/letsencrypt/live/example.in/example.pem
mode http
http-request set-header X-Forwarded-Proto https
default_backend example
backend example
stick-table type binary len 32 size 30k expire 30m
acl clienthello req_ssl_hello_type 1
acl serverhello rep_ssl_hello_type 2
tcp-request inspect-delay 5s
tcp-request content accept if clienthello
tcp-response content accept if serverhello
stick on payload_lv(43,1) if clienthello
stick store-response payload_lv(43,1) if serverhello
server varnish 127.0.0.1:8081 check
Plan:
HAproxy :
Here I have to configure, if user execute exmaple.com and www.example.in then redirect to https://example.in -For https
if example1.in then redirect to www.exmaple1.inand so on.