Search code examples
haproxymarathondcos

How do I route by path in DC/OS?


Let's say I have a single domain fooapi.com and two versions of the API: v1 and v2. How do I configure HAProxy in the marathon.json file so that both API versions can live behind the same domain but with a different path? Eg. fooapi.com/v1/ and fooapi.com/v2/.

The following configuration doesn't work (latest DCOS):

"labels": {
"HAPROXY_0_VHOST": "fooapi.com",
"HAPROXY_DEPLOYMENT_GROUP": "api-grp",
"HAPROXY_GROUP": "external",
"HAPROXY_0_PATH": "/v1"
}

Solution

  • After reading through the Marathon-lb docs, I've solved it by adding the HAPROXY_0_HTTP_BACKEND_PROXYPASS_PATH config parameter:

    "labels": {
    "HAPROXY_0_VHOST": "fooapi.com",
    "HAPROXY_DEPLOYMENT_GROUP": "api-grp",
    "HAPROXY_GROUP": "external",
    "HAPROXY_0_HTTP_BACKEND_PROXYPASS_PATH": "/v1",
    "HAPROXY_0_PATH": "/v1"
    }