Same host different paths on docker containers

Issue:
Hello, I have a Docker Compose file for frontend1. I want to configure it to handle all paths except those starting with sitemap or rss. However, for the frontend2 container, I only want it to respond to requests directed at the sitemap and rss paths.

Regex Patterns:

(www\.)?(foobar.com\/(?!(sitemap?.+|rss?.+)).+) - Handles all paths except sitemap and rss.
(www\.)?(foobar.com\/((sitemap?.+|rss?.+))) - Handles only sitemap paths.

Question:
I'm looking for advice on how to implement these regex patterns effectively within my Docker Compose configuration. Specifically, how can I ensure that frontend1 handles all paths except sitemap and rss, while frontend2 responds only to requests directed at the sitemap and rss paths?

Docker Compose Configuration:

frontend1:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fen"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

  labels:
    - traefik.enable=true
    - "traefik.http.routers.frontendsite.rule=Host(`foobar.com`) || Host(`www.foobar.com`)"
    - traefik.http.routers.frontendsite.entrypoints=websecure
    - traefik.http.routers.frontendsite.tls=true
    - traefik.http.routers.frontendsite.tls.certresolver=myresolver
    - traefik.http.routers.frontendsite.service=frontendsite
    - traefik.http.services.frontendsite.loadbalancer.server.port=3001
    - traefik.http.routers.frontendsite.middlewares=mywwwredirect
    - traefik.docker.network=supabase

  restart: always

frontend2:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fens"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

  labels:
    - traefik.enable=true
    - traefik.http.services.frontendsite.loadbalancer.server.port=3001
    - traefik.docker.network=supabase

  restart: always

Thanks:
Thank you in advance for any assistance or insights you can provide!

@bluepuma77

Version Trafeik 3.0

Simple router rule:

.rule=Host(`example.com`) && ( PathPrefix(`/sitemap`) || PathPrefix(`/rss`) )

You only need this for the one matching. The rule is longer, therefore has higher priority, will be matched first.

Hello, @bluepuma77

Like that same router ?

frontend1:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fen"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

  labels:
    - traefik.enable=true
    - "traefik.http.routers.frontendsite.rule=Host(`foobar.com`) && ( PathPrefix(`/sitemap`) || PathPrefix(`/rss`) )"
    - traefik.http.routers.frontendsite.entrypoints=websecure
    - traefik.http.routers.frontendsite.tls=true
    - traefik.http.routers.frontendsite.tls.certresolver=myresolver
    - traefik.http.routers.frontendsite.service=frontendsite
    - traefik.http.services.frontendsite.loadbalancer.server.port=3001
    - traefik.http.routers.frontendsite.middlewares=mywwwredirect
    - traefik.docker.network=supabase

  restart: always

frontend2:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fens"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

  labels:
    - traefik.enable=true
    - "traefik.http.routers.frontendsite.rule=Host(`foobar.com`) || Host(`www.foobar.com`)"
    - traefik.http.services.frontendsite.loadbalancer.server.port=3001
    - traefik.docker.network=supabase

  restart: always

Longer rule for the one for sitemap/rss.

Note hat using sh in command will result in signals not being passed to the script running AFAIK. So if you run multiple instances and want a rolling update with graceful shutdown, this won’t work.

frontend1:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fen"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

    labels:
              - traefik.enable=true
              - "traefik.http.routers.testsite.rule=Host(`foobar.com`) && ( PathPrefix(`/sitemap.xml`) || PathPrefix(`/rss.xml`) ) "
              - traefik.http.routers.testsite.entrypoints=websecure
              - traefik.http.routers.testsite.tls=true
              - traefik.http.routers.testsite.tls.certresolver=myresolver
              - traefik.http.routers.testsite.service=testsite
              - traefik.http.services.testsite.loadbalancer.server.port=3001
              - traefik.http.routers.testsite.middlewares=mywwwredirect
              - traefik.docker.network=supabase

  restart: always

frontend2:
  image: docker.io/foxsnow/next-frontend:test
  command: >
    sh -c "npm run feb && npm run fens"

  environment:
    - NEXT_PUBLIC_SERVER_URL=$NEXT_PUBLIC_SERVER_URL
    - NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL

  networks:
    - supabase
    - bridge

  labels:
              - traefik.enable=true
              - "traefik.http.routers.testsitetwo.rule=Host(`foobar.com`) "
              - traefik.http.routers.testsitetwo.entrypoints=websecure
              - traefik.http.routers.testsitetwo.tls=true
              - traefik.http.routers.testsitetwo.tls.certresolver=myresolver
              - traefik.http.routers.testsitetwo.service=testsite
              - traefik.http.services.testsite.loadbalancer.server.port=3001
              - traefik.http.routers.testsitetwo.middlewares=mywwwredirect
              - traefik.docker.network=supabase
  restart: always

When I made like that its giving 404 error page.
because same router on 2 host how I can make load balance ??

@bluepuma77

You need separate services with separate router names. Sitemap gets the longer rule as you had it in the compose file.

You can centralize http-to-https redirect and TLS on entrypoints, see simple Traedik example.

This example its not showing what I want.
Can you edit my compose file and show me what you realy want to show Sir ?

frontend1:
  labels:
    - traefik.enable=true
    - traefik.http.routers.sitemap-rss.rule=Host(`foobar.com`) && ( PathPrefix(`/sitemap`) || PathPrefix(`/rss`) )
    - traefik.http.services.sitemap-rss.loadbalancer.server.port=3001
    - traefik.docker.network=supabase

frontend2:
  labels:
    - traefik.enable=true
    - traefik.http.routers.frontendsite.rule=Host(`foobar.com`) || Host(`www.foobar.com`)
    - traefik.http.services.frontendsite.loadbalancer.server.port=3001
    - traefik.docker.network=supabase

Hello @bluepuma77,
When I made like that sir
- "traefik.http.routers.testsite.rule=Host(test.foobar.com) && !Path(/{sitemapath:(sitemap?.+|rss?.+)})"
I still can go to test.foobar.com/sitemap.xml
how is still happen ?
Thank you Sir.

I explained how it should be done.

Why do you use Path and think you can place a Regex inside? Please read the v3 docs.

Documentation style needs to change. When I look in google path regex it not seem Sir.