How to avoid IP and port usage and redirect only to SSL domain

Hi, I'm using traefik 3.1.2 via docker, and it works so far very good.
I was adding a docker compose for local-ai and want to avoid that the IP and port can be called directly like http://123.456.789.0:8888 so traefik will be redirecting everything to the domain.
I have the following labels setup in my local-ai docker compose file in use

 labels:
       - "traefik.enable=true"
       - "traefik.docker.network=proxy"
       - "traefik.http.routers.local-ai-secure.entrypoints=websecure"
       - "traefik.http.routers.local-ai-secure.rule=Host(`sub.domain.com`)"
       - "traefik.http.routers.local-ai-secure.service=local-ai"
       - "traefik.http.routers.local-ai-secure.tls=true"
       - "traefik.http.services.local-ai.loadbalancer.server.port=8080"
       - "traefik.http.routers.local-ai-secure.tls.certresolver=letsencrypt"
       - "traefik.http.routers.local-ai-secure.middlewares=secureHeaders@file"

What's wrong that I can still call the IP and getting and result. I'm using the same config for "baserow" at port 9000 and cannot call the IP and port directly and getting a loading error, which is ok for me.
What do I have to change with my labels config? Thanks in advance

You didn’t share the compose file of your service, but you probably used ports: to open the ports on the host.

Remove that, as Traefik will use the Docker network, within all ports are reachable.

Compare to simple Traefik example.

1 Like

Well, that was easy and I guess I learned something new about how to do it right. Thanks a lot. :innocent:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.