Hi everyone,
I am trying to serve a http service on port 8080. but It only works when I go to https://localhost:8080
but doesn't work when I go to http://localhost:8080
. What I want is to forward the http traffic that comes in to 8080 to https protocol.
So that when I visit http://localhost:8080
, It would still get a response.
Here's a minimal code of what I'm trying to do -
services:
traefik:
command:
- "--providers.docker"
- "--entrypoints.customweb.address=:8080"
- "--log.level=DEBUG"
depends_on:
- whoami
image: traefik:v2.11
ports:
- mode: host
published: 8080
target: 8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: traefik/whoami
labels:
- traefik.http.routers.whoami.entrypoints=customweb
- traefik.http.routers.whoami.rule=Host(`localhost`)
- traefik.http.routers.whoami.tls=true
- traefik.http.routers.whoami.service=whoami
- traefik.http.services.whoami.loadbalancer.server.port=80
That should simply work with RedirectScheme midleware (doc).
Redirect middleware seem not to work.
It's redirecting https://localhost:8080
to https://localhost:443
services:
traefik:
command:
- --providers.docker
- --entrypoints.customweb.address=:8080
- --log.level=DEBUG
depends_on:
- whoami
image: traefik:v2.11
ports:
- mode: host
published: 8080
target: 8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: traefik/whoami
labels:
- traefik.http.routers.whoami.entrypoints=customweb
- traefik.http.routers.whoami.rule=Host(`localhost`)
- traefik.http.routers.whoami.tls=true
- traefik.http.routers.whoami.service=whoami
- traefik.http.services.whoami.loadbalancer.server.port=80
- traefik.http.middlewares.redirect-mw.redirectscheme.scheme=https
- traefik.http.middlewares.redirect-mw.redirectscheme.permanent=true
- traefik.http.routers.whoami.middlewares=redirect-mw
The documentation is your friend:
port
The port
option defines the port of the new URL.
I added the port but that didn't work either.
I still get -
curl -Lk http://localhost:8080
404 page not found
services:
traefik:
command:
- --providers.docker
- --entrypoints.customweb.address=:8080
- --log.level=DEBUG
depends_on:
- whoami
image: traefik:v2.11
ports:
- mode: host
published: 8080
target: 8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: traefik/whoami
labels:
- traefik.http.routers.whoami.entrypoints=customweb
- traefik.http.routers.whoami.rule=Host(`localhost`)
- traefik.http.routers.whoami.tls=true
- traefik.http.routers.whoami.service=whoami
- traefik.http.services.whoami.loadbalancer.server.port=80
- traefik.http.middlewares.redirect-mw.redirectscheme.scheme=https
- traefik.http.middlewares.redirect-mw.redirectscheme.permanent=true
- traefik.http.middlewares.redirect-mw.redirectscheme.port=8080
- traefik.http.routers.whoami.middlewares=redirect-mw
Ok, maybe it doesn't work anymore. It works with http
when you remove tls
. I know that people where complaining that you could do a http
connection even though tls
was enabled.
Here we go (doc):
When a TLS section is specified, it instructs Traefik that the current router is dedicated to HTTPS requests only (and that the router should ignore HTTP (non TLS) requests).
Yes, I also reached similar conclusion, maybe it doesn't work.
I tried a lot and finally ended up in forum as last resort!
Thank you!