Accessing Service under specific PATH incl. PORT Forwarding does not work

Hi Community,

I have got a problem and won't find a solution (after reading the doc or searching for) :frowning: . So I hope, someone can help me :slight_smile:

I'm using Portainer at my local home server and want to use Traefik as a proxy, so I can reach my services like:

home.fritz.box/openhab
home.fritz.box/nodered
....

Like the documentation provides some samples with whoami, I have started with that:

version: '3.9'

services:
  traefik:
    image: traefik:v2.9.6
    container_name: traefik
    restart: always
    
    # Enables the web UI and tells Traefik to listen to docker
    command: 
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    
    ports:
      # The HTTP port
      - 80:80
      # The HTTPS / TLS port
      - 443:443      
      # The Web UI (enabled by --api.insecure=true)
      - 8080:8080
    networks:
     - home-proxy-network
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - traefik-volume:/etc/traefik

...
services:
  whoami:
    image: traefik/whoami
    container_name: whoami
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`home.fritz.box`)"
      - "traefik.http.routers.whoami.rule=Path(`/whoami`)"
      - "traefik.http.routers.whoami.entrypoints=web"
    networks:
     - home-proxy-network
...

And it works as expected :slight_smile:

So the next step is to configure it for openhab / node-red.

Here the compose file:

version: "3.9"

services:
  nodered:
    image: nodered/node-red:3.0.2
    container_name: nodered
    restart: always
    environment:
      - TZ=Europe/Berlin
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nodered.rule=Host(`home.fritz.box`)  && Path(`/nodered`)"
      - "traefik.http.routers.nodered.entrypoints=web"
      - "traefik.http.services.nodered.loadbalancer.server.port=1880"
    networks:
      - home-proxy-network
    volumes:
      - node-red-volume:/data

The challenge here is, that the requests needs to be forwarded to the port 1880, so I have used the "traefik.http.services.nodered.loadbalancer.server.port" option.

But it wont work!

I only get:

Cannot GET /nodered

If I wont set the PATH rule, then it works and I can reach node-red under home.fritz.box. But that is not, what I want.

...
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nodered.rule=Host(`home.fritz.box`)"
      - "traefik.http.routers.nodered.entrypoints=web"
      - "traefik.http.services.nodered.loadbalancer.server.port=1880"
...

The same for openhab.

Is it not possibe to use the PATH rule in combination with the loadbalancer.server.port option?

Who can help? :slight_smile:

Cheers!
Christian

You should try PathPrefix instead of Path.

Please note that placing applications under a path usually only works if your application is path-aware and you can somewhere tell it the path to use. Otherwise redirects and links from the application won’t work as they will use the wrong path.

Thank you for your response.

I will test it later. You're right, if an app isn't path aware, there are then other problems.

What would be a better alternative?

My first approach was to set "sub" domains. But I'm not sure how to do it.

Instead of home.fritz.box/openhab something like openhab.home.fritz.box

Every good hint is welcome :slightly_smiling_face:

Thanks!

Yes, I think sub-domain is the better approach.

If you want your services to be available externally, you can set the sub-domain in your DNS as CNAME to your DynDNS (or other) domain name.