我在用Traefik将http重定向到https流量时遇到了一个小问题。到目前为止,我的带有acme的https路由器运行良好,但我有两个问题要克服。
https://domain
以通过https路由。否则,它将尝试通过http路由并获得404。https://domain
时,它大部分也能工作,但在某些路径中,由于没有任何原因,它将尝试通过http路由,并得到一个404。如何确保路由总是对路由中的每个路径使用https,无论https是否被键入到地址栏中?
入口点是名称http
和https
。我的部分工作安排:
- "traefik.enable=true"
- traefik.port=8000
- traefik.backend=myapp
- traefik.http.routers.myapp.rule=Host(`sub.mydomain.com`)
- "traefik.http.routers.myapp.entrypoints=https"
- "traefik.http.routers.myapp.tls.certresolver=myresolver"
# redir http to https
- "traefik.http.routers.myapp-secure.rule=Host(`sub.mydomain.com`) && PathPrefix({p:.+})"
- "traefik.http.routers.myapp-secure.entrypoints=https"
- "traefik.http.middlewares.myapp-secure.redirectscheme.scheme=https"
- "traefik.http.routers.myapp.middlewares=myapp-secure"
- "traefik.http.routers.myapp-secure.tls=true"
发布于 2020-03-03 18:20:46
在traefik服务本身上添加以下标签,所有HTTP通信将被重定向到HTTPS
- traefik.http.middlewares.https_redirect.redirectscheme.scheme=https
- traefik.http.middlewares.https_redirect.redirectscheme.permanent=true
- traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)
- traefik.http.routers.http_catchall.entrypoints=http
- traefik.http.routers.http_catchall.middlewares=https_redirect
有关使用Traefik的更多信息和完整示例,请参阅这里。
发布于 2021-08-11 23:16:08
另外,如果您使用命令而不是标签来配置它,则可以添加以下内容
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
发布于 2022-05-12 11:05:11
要将以下内容添加到此回答中,应该只对不匹配Letsencrypt的ACME验证的请求重定向
"traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`) && !PathPrefix(`/.well-known/acme-challenge/`)"
https://stackoverflow.com/questions/60510232
复制相似问题