title: haproxy - how to do virtualhost and https forwarding?
body: <p>Can anyone please advise how to do this with haproxy?</p>
  
  <p>I have this haproxy setup, where i get https request and redirect it to localhost 8888.
  but now i have more request i need to apply virtual host </p>
  
  <pre><code>https://python.stackoverflow.com = goes to as it is http://localhost:8888
  https://cplusplus.stackoverflow.com = goes to /var/www/html/cgi-project
  https://chat.stackoverflow.com = goes to /var/www/html/microchat
  https://zendframework.stackoverflow.com = goes to /var/www/html/zf2/public
  
  global
      log 127.0.0.1 local0 debug
      maxconn 8000
      user    haproxy
      group   haproxy
  defaults
      log     global
      option  httplog
      option  dontlognull
      option  http-server-close
      option  redispatch
      retries 3
      mode    http
      maxconn         5000
      timeout connect  5s
      timeout client  30s
      timeout server  30s
      timeout tunnel  12h
  frontend www
      bind     :8881
      option   forwardfor
      redirect scheme https if !{ ssl_fc }
  frontend lb
      bind   :8882 ssl crt /etc/stunnel/all.pem ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA
      option forwardfor
      reqadd X-Forwarded-Proto:\ https
      default_backend  api
      acl is_websocket hdr(Upgrade)  -i WebSocket
      acl is_websocket hdr_beg(Host) -i ws
      acl is_api       hdr_beg(Host) -i api
      use_backend ws  if is_websocket
      use_backend api if is_api
  backend api
      balance roundrobin
      server  service 127.0.0.1:8888 weight 1 maxconn 2500 check
  backend ws
      balance roundrobin
      server  service 127.0.0.1:8888 weight 1 maxconn 2500 check
  </code></pre>