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 :
Network:
sudo docker network create --attachable --driver overlay apache-network

Services:
mydomain.example/

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

mydomain.example/myapp
sudo docker service create
–mode replicated
–replicas 1
–name myapp-Service
–network apache-network
–endpoint-mode dnsrr
somewhere/myapp:1.0

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 :-/

Example:
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 ?