Comment 0 for bug 1154179

Revision history for this message
Marius B. Kotsbak (mariusko) wrote :

I have tried reusing one haproxy instance for serving different services with different virtual hosts (same IP address, all on port 80).

What I have tried:
* Using bind:

haproxy-jenkins:
    services: |
        - service_name: node-app_service
          service_host: "0.0.0.0"
          service_port: 80
          service_options: [balance leastconn, "bind a.virtual.hostname.com:80"]
          server_options: maxconn 100

        - service_name: node-app2_service
          service_host: "0.0.0.0"
          service_port: 80
          service_options: [balance leastconn, "bind another.virtual.hostname.com:80"]
          server_options: maxconn 100

does not work (gives "cannot bind socket") because the IP behind the hostname is not bound to the machine.

* Using reqiallow:

haproxy-jenkins:
    services: |
        - service_name: node-app_service
          service_host: "0.0.0.0"
          service_port: 80
          service_options: [balance leastconn, "reqiallow ^Host:\\ a.virtual.hostname.com$"]
          server_options: maxconn 100

        - service_name: node-app2_service
          service_host: "0.0.0.0"
          service_port: 80
          service_options: [balance leastconn, "reqiallow ^Host:\\ a.virtual.hostname.com$"]
          server_options: maxconn 100

also does not work, since all entries must be set to "0.0.0.0" (same as with bind) and the second fail to bind to that address.

The proper solution is probably to use frontend and backends with ACL:

http://www.techrawr.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts/

but it is possible to do with the current configuration options.