larsks / blog.oddbit.com

3 stars 0 forks source link

post/2022-06-20-traefik-multiple-listeners/ #26

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Directing different ports to different containers with Traefik :: blog.oddbit.com

This post is mostly for myself: I find the Traefik documentation hard to navigate, so having figured this out in response to a question on Stack Overflow, I’m putting it here to help it stick in my head. The question asks essentially how to perform port-based routing of requests to containers, so that a request for http://example.com goes to one container while a request for http://example.com:9090 goes to a different container.

https://blog.oddbit.com/post/2022-06-20-traefik-multiple-listeners/

dusty-cjh commented 1 year ago

Hi master, for example I have a container named x-one and which is listening on port 54321. the x-one is labeled with x-one. localhost, when traefik started, we can visit x-one by the address: http://x-one.localhost:54321

But Now, I want to visit x-one. localhost, and which should be automaticly proxyed by traefik from 80 port to 54321 port inside traefik, just like what nginx did in reverse proxy, how could I achieve that?

crisjohn02 commented 9 months ago

add that line under labels inside your x-one container

labels:
    - traefik.http.routers.x-one.rule=Host(`x-one.localhost`)
    - traefik.http.services.x-one.loadbalancer.server.port=54321

and you don't need to expose the port 54321as long as they are in the same network.