I updated my Rocky Linux 8.7 to 9.1, on 8.7 my Cockpit worked through Traefik with this YML.
---
http:
routers:
cockpit:
rule: "Host(`cockpit.mywebsite.com`)"
service: cockpit-service
priority: 1000
tls:
certresolver: myresolver
entryPoints:
- websecure
services:
cockpit-service:
loadBalancer:
servers:
- url: "http://192.168.0.54:9090"
...
Now I have this error and when I change the address to 127.0.0.1:9090 I also have a Bad Gateway. My Traefik is under Docker and works perfectly with other containers.
The following solution has been tested on Ubuntu server 22.04, but might be applicable in your case too.
The problem is that Traefik is configured to use a TLS resolver to terminate the HTTPS connection, which means that it will try to connect to cockpit using HTTP. However, cockpit is configured to redirect HTTP connections to HTTPS, which will cause an infinite loop of redirects.
I'm sure there are better ways to deal with this, but one quick and easy fix is to:
Open the file and enter the following text:
save it and restart cockpit using
Now you should be able to access cockpit at https://cockpit.mywebsite.com with the traefik cert.
However, it should be noted that anyone on your network may access your cockpit instance using HTTP by accessing the IP:port directly.