Redirect of top level domain and subdomains -> too many redirects (different backends)

I am currently trying to figure out if the software itself causes the problem or the configuration I wrote in HAProxy, so apologies if it’s not HAProxy related.

I need to redirects to two different services in Docker Swarm, one of them should be selected when the toplevel domain (e.g. institute.org), the other when a subdomain (e.g. internal.institute.org) is used. I am pretty sure it’s a common thing but I get “too many redirects” in the browser, so apparently something goes wild and ends up in an infinite loop.

Here is my latest try :wink:

acl ACL_internal.institute.org hdr(host) -i internal.institute.org
acl ACL_institute.org hdr(host) -i institute.org
use_backend be_internal.institute.org if ACL_internal.institute.org
use_backend be_institute.org if ACL_institute.org !ACL_internal.institute.org

and then down the line (but this shouldn’t be the problem)

backend be_institute.org
    balance roundrobin
    dynamic-cookie-key INSTITUTE
    cookie SRVID insert dynamic
    option httpchk HEAD /
    default-server check maxconn 20
    server-template some-service- 1 some-service_foo:80 check resolvers docker init-addr libc,none

backend be_internal.institute.org
    balance roundrobin
    dynamic-cookie-key OPENDATAKM3NET
    cookie SRVID insert dynamic
    option httpchk HEAD /
    default-server check maxconn 20
    server-template some-service- 1 some-service_foo:42023 check resolvers docker init-addr libc,none

Hello,

As I don’t see any redirection in this config, I think the redirects are not from Haproxy but from your backends.
To debug, a good start will be to check logs, to see where requests are shipped. After this you can try to make a call with a cli tool like Curl and see who is sending redirect and why.

On the other hand, you could use a tool like traefik on top on your docker swarm. Once deployed and well configured, you juste have to use it as backend in haproxy and it take care to ship requests to the right service.

1 Like

Yes, I understand you don’t need redirect, there is no redirect in the config you shown.

That’s why I’m guessing the redirect is coming from your app.

1 Like

I see, thanks! (sorry for the deleted post, I misunderstood something and now my answer makes no sense ;))

yes, I am digging through the logs and I will also see if I can make use of Traefik, but that will require a bigger change in the current system :wink: