5

I use a HAPROXY container as an entry point for a virtual HPC cluster. Depending on a prefix the request is forwarded to different containers.

:80/foswiki/ -> :80/foswiki/
:80/kibana/ -> :80/kibana/
:80/graphite-api/ -> :80/graphite-api/
...

The config I use is pretty simple:

frontend http-in
    bind *:80
    acl uri_foswiki path_beg /foswiki
    use_backend srv_foswiki if uri_foswiki
    # gitlab
    default_backend srv_gitlab

backend srv_foswiki
    balance roundrobin
    cookie SERVERID insert
    option httpclose
    option forwardfor
    server foswiki 172.17.0.3:80 cookie

The thing is that there are webserver that serve the website directly as root, without a prefix. 'Graphite-web', e.g. or the gitlab image.

I try to cut the prefix and forward it further, but what I really want, is that the haproxy keeps the prefix in the path and that it is transparent to the backends server. If I click on 'gitlab_server:80/dashboard/' it shoult come out as 'frontend_ip:80/gitlab/dashboard'.

backend srv_gitlab
    balance roundrobin
    #cookie SERVERID insert
    mode http
    reqrep ^([^\ ]*)\ /gitlab/(.*)     \1\ /\2
    balance roundrobin
    option forwardfor
    server gitlab 172.17.0.18:80 cookie

I don't think it is a hard thing to do, but it seems to me, that my google skills are somewhat crippled. Every time I end up with rewrite rules that do not keep the prefix.

Anyone? Christian

EDIT: The internal IP addresses are not reachable by the user...

  • So is the problem that the Appserver redirects you to locations without the prefix? – Felix Frank Jun 18 '14 at 10:20
  • yes. I rewrite the URL 'GLOBAL_IP/gitlab/' to 'INTERNAL_IP/' (transparent to the end user agent) and afterwards the gitlab-webapp issues 'GLOBAL_IP/dashboards/', for which I would have to setup a second rewrite. I would like to have a auto-prefixing for all the links. But maybe I have to cope with the internal-webserver and his HOST_NAME. It would be cleaner if I do not have to bother with the internal webserver. – kniepbert Jun 18 '14 at 12:06
  • Ah, so you're looking for a regex that will strip the leading gitlab/ from URIs. I'll see about an answer. – Felix Frank Jun 18 '14 at 13:02
1

To get rid of leading parts of the URI, try

reqrep ^(GET|POST)\ /gitlab/(.*) \1\ /\2

i.e., extract the HTTP method into \1 and the path following the gitlab root into \2, then catenate them to a full request.

Note that this may not cut it for many applications, because the appserver doesn't know that clients are supposed to request everything from inside a virtual gitlab/ root directory. Therefor, redirects will apparently "strip" the important root directory.

Such scenarios are solved more easily e.g. with nginx and its mod_proxy or even Apache.

  • But this would get rid of '/gitlab/' for the future, wouldn't it? I am looking for something that works like an inline-frame. If I click the link '^/dashboard/' within gitlab it should be expaned to '/gitlab/dashboard/' to be able to forward it at the haproxy-layer to the gitlab server in the backend. – kniepbert Jun 18 '14 at 13:28
  • I see. haproxy is surprisingly bad at this, sadly (i.e., free form response header mangling). I suggest nginx in between, or even replacing haproxy. – Felix Frank Jun 18 '14 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.