0

My marathon-lb configuration:

"labels": {
    "HAPROXY_GROUP": "external",
    "HAPROXY_0_VHOST": "test.com",
    "HAPROXY_0_MODE": "http"
  }

I want it route only requests like test.com/12345 to internal endpoint /results?q=123. How to achieve that?

P.S. Nginx rule for the same purpose looks like:

location ~* /[\w\-]+?$ {
         proxy_pass http://127.0.0.1:8094;
         rewrite ^/([\w\-]+?)$ //results?q=$1? break;
    }
Nikita
  • 4,435
  • 3
  • 24
  • 44

1 Answers1

1

As you probably know marathon-lb is HAProxy plus some wrappers. You can add a redirect to HAProxy configuration, by using HAPROXY_0_BACKEND_HTTP_OPTIONS label. There's a legacy reqrep statement which you may find convenient and you can also go for 301 redirect. For example you can do:

"HAPROXY_0_BACKEND_HTTP_OPTIONS": " reqrep ^/([\w\-]+?)$ /results?q=\\1 \n",

or

"HAPROXY_0_BACKEND_HTTP_OPTIONS": " acl is_foo path -i /foo \n redirect code 301 location /bar if is_foo\n",

Note double spaces for indent. Not that you'll have to play with escapes to make it work.

riemann
  • 435
  • 4
  • 12
  • 1
    It looks impossible to configure/learn haproxy/acl syntax in one evening, so I set up extra nginx router. – Nikita Aug 03 '17 at 11:25