HAProxy community

Haproxy - Routing failing with nodejs app

Hi everyone,

I was following this guide, unfortunately I’m facing to the following issue :

  1. When I try to reach “mydomain.example/myapp”, I’m getting “Cannot GET /myapp”

  2. As a test, I created 2 containers Apache and Nginx, and it was working fine (I tested with /nginx and /apache)

  3. When I check haproxy report, I can see “myapp” “Active UP” with the correct IP (from the overlay network) on port 49000.

Here is my haproxy.cfg file: https://pastebin.com/jDmbSqN6

Docker commands :
sudo docker network create --attachable --driver overlay apache-network


sudo docker service create
–mode replicated
–replicas 1
–name home-Service
–network apache-network
–endpoint-mode dnsrr

sudo docker service create
–mode replicated
–replicas 1
–name myapp-Service
–network apache-network
–endpoint-mode dnsrr

myapp is container with a NodeJS server that host a small webapp
If I remove HAProxy, and I recreate the service “myapp” and replace “endpoint-mode” by the publishing port (-p 49000: 49000), myapp works fine.

Any suggestions on how I can troubleshoot or resolve this issue ? :-/

Thanks in advance!

root cause:
Haproxy was trying to reach “/usr/share/nginx/html/myapp”, when my application is located in the default path (so without “/usr/share/nginx/html/”)

So I added a Regex in the following backend, to remove “myapp”:
reqrep reqrep ^([^\ ]\ /)web1[/]?(.) \1\2

I also tried : http-request set-uri http://%[req.hdr(Host)]

I can successfully open the home page of “myapp” now, however any links will redirect me to a 404 page :-/

myWebsite.com/myapp -> when clicking on a link like href="/mySubfolder" -> the url will be myWebsite.com/mySubfolder (that didn’t exist).

Did I miss something in the configuration ? How can I resolve this issue ?