This is a weird scenario, but anyways, this is the thing:
I am hosting some containers at home, and my ISP does not allow exposing ports below 1024. Therefore I made this way:
Traefik ports 80, 443 and 8080 are binded to ports 80, 443 and 8080 in my device, respectively. In the router I had to make port forwarding like this:
external port 8000 forwards to my device on port 80, thus reaching traefik:80
external port 4433 forwards to my device on port 443, thus reaching traefik:443
then to access my services I need to either use HTTP with the following:
http://traefik.mydomain.duckdns.org:8000
OR
https://traefik.casarin.duckdns.org:4433
the problem is that I don't want to have a 404 page not found when accessing the HTTP protocol, since my services are only listening to HTTPS, so I want Traefik to make some redirects.
I tried some stuffs, I could get a redirect from HTTP to HTTPS, but since the ports differ from Traefik ports, the redirects were like from HTTP:8000 to HTTPS:443(port omitted in browser), instead of from HTTP:8000 to HTTPS:4433. This is the only way external devices can access my services on HTTPS.
This is my docker-compose.yml for Traefik:
traefik:
image: traefik:v3.2
container_name: traefik
networks:
- selfhost
volumes:
- ./traefik.yml:/etc/traefik/traefik.yml:ro
- ./dynamic.yml:/config/dynamic.yml:ro
- ./letsencrypt:/letsencrypt:rw
restart: unless-stopped
ports:
- 8080:8080
- 80:80
- 443:443
environment:
DUCKDNS_TOKEN: mytoken
This is my static traefik.yml:
entryPoints:
web:
address: :80
websecure:
address: :443
http:
tls:
certResolver: letsencrypt
domains:
- main: mydomain.duckdns.org
sans:
- "*.mydomain.duckdns.org"
certificatesResolvers:
letsencrypt:
acme:
email: myemail
storage: /letsencrypt/acme.json
dnsChallenge:
provider: duckdns
# disablePropagationCheck: true
# delayBeforeCheck: 60s
resolvers:
- "1.1.1.1:53"
- "8.8.8.8:53"
api:
insecure: true
providers:
file:
filename: /config/dynamic.yml
watch: true
log:
level: DEBUG
This is my dynamic.yml:
http:
middlewares:
redirect-to-https:
redirectScheme:
scheme: https
port: 4433
permanent: true
routers:
whoami:
rule: Host(`whoami.mydomain.duckdns.org`)
service: whoami
entryPoints:
- websecure
portainer:
rule: Host(`portainer.mydomain.duckdns.org`)
service: portainer
entryPoints:
- websecure
traefik:
rule: Host(`traefik.mydomain.duckdns.org`)
service: traefik
entryPoints:
- websecure
redirect-http:
rule: HostRegexp(`{host:.+}`)
entryPoints:
- web
middlewares:
- redirect-to-https
service: noop-service
services:
whoami:
loadBalancer:
servers:
- url: http://whoami:80
portainer:
loadBalancer:
servers:
- url: http://portainer:9000
traefik:
loadBalancer:
servers:
- url: http://localhost:8080
noop-service:
loadBalancer:
servers: []
This way I am getting a 404 page not found when reaching http://whoami.mydomain.duckdns.org:8000
, instead of redirecting WITH the port 4433...
What to do?