如何使用Traefik 2.0和Docker Compose标签将http重定向到https? [英] How to redirect http to https with Traefik 2.0 and Docker Compose labels?
问题描述
请注意,这是Traefik V2问题。我在V1上有一个解决方案,但V2完全需要重新安装。
以上应该重定向从http://whoami.mysite.com 到http s ://whoami.mysite.com。
This above is supposed to redirect http://whoami.mysite.com to https://whoami.mysite.com.
- http s 运行良好。
- http不会重定向到https并引发错误404。
- The https is working nicely.
- The http don't redirect to https and raise an error 404.
没有其他文件。目前,所有内容都在此Docker-compose.yml中,因为它是准备进一步部署的测试。
There is no other file. All is in this Docker-compose.yml for the moment since it is a test to prepare further deployement.
version: "3.3"
services:
traefik:
image: "traefik:v2.0"
container_name: "traefik"
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.web-secure.address=:443"
- "--certificatesresolvers.myhttpchallenge.acme.httpchallenge=true"
- "--certificatesresolvers.myhttpchallenge.acme.httpchallenge.entrypoint=web-secure"
#- "--certificatesresolvers.myhttpchallenge.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
- "--certificatesresolvers.myhttpchallenge.acme.email=me@mail.com"
- "--certificatesresolvers.myhttpchallenge.acme.storage=/letsencrypt/acme.json"
labels:
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
image: "containous/whoami"
container_name: "whoami"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.mysite.com`)"
- "traefik.http.routers.whoami.entrypoints=web"
- "traefik.http.routers.whoami.middlewares=redirect-to-https@docker"
- "traefik.http.routers.whoami-secured.rule=Host(`whoami.mysite.com`)"
- "traefik.http.routers.whoami-secured.entrypoints=web-secure"
- "traefik.http.routers.whoami-secured.tls=true"
- "traefik.http.routers.whoami-secured.tls.certresolver=myhttpchallenge"
推荐答案
我建议在这里查看docs 入口重定向80> 443
I suggest to take a look here at the docs Entrypoint redirect 80 > 443
这对我有用,如果要将所有流量从端口80重定向到443,这是最好的解决方案。
This worked for me and is the best solution if you want all traffic redirected from port 80 to 443.
--entrypoints.web.address=:80
--entrypoints.web.http.redirections.entryPoint.to=websecure
--entrypoints.web.http.redirections.entryPoint.scheme=https
--entrypoints.web.http.redirections.entrypoint.permanent=true
--entrypoints.websecure.address=:443
注意:
NOTE:
周围有很多例子。只需看一下websecure。
there are so many examples around. Just take a look at websecure.
有时它是写为网络安全的。
Sometimes it is written web-secure.
希望有帮助; o)
这篇关于如何使用Traefik 2.0和Docker Compose标签将http重定向到https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!