gpt4 book ai didi

docker - 使用 traefik 将 ssl 路由到不同 docker 上的不同服务器

转载 作者:太空宇宙 更新时间:2023-11-03 14:23:48 25 4
gpt4 key购买 nike

我对此一窍不通,但在阅读了一些好的指南后,我遇到了以下问题......

我在 Ubuntu 上设置了一个家庭服务器,使用 docker 为不同的应用程序运行容器; plex、我的世界、portainer 和 traefik。我已经成功地设置了带有反向代理的 traefik,https,带有 lets encrypt 和 duckdns.org 的 ssl 路由。

从昨天开始,我已经为我的家庭自动化设置了一个带有 hass.io 的 RaspberryPi。要让 hass.io 连接到我的 Alexa 帐户,我需要它是 https,因为我已经使用 traefik 来证明我与服务器的连接......我想我也可以使用它......

但我无法让它工作。我如何设置 traefik 以便它也可以处理我服务器上 docker 之外的服务器?`

来 self 的 docker-compose.yaml

 #Portainer - WebUI for Containers
portainer:
image: portainer/portainer
hostname: portainer
container_name: portainer
restart: always
command: -H unix:///var/run/docker.sock
# ports:
# - "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${USERDIR}/docker/portainer/data:/data
- ${USERDIR}/docker/shared:/shared
environment:
- TZ=${TZ}
networks:
- traefik_proxy
labels:
- "traefik.enable=true"
- "traefik.backend=portainer"
- "traefik.frontend.rule=Host:portainer.${DOMAINNAME}"
# - "traefik.frontend.rule=Host:${DOMAINNAME}; PathPrefixStrip: /portainer"
- "traefik.port=9000"
- "traefik.docker.network=traefik_proxy"
- "traefik.frontend.headers.SSLRedirect=true"
- "traefik.frontend.headers.STSSeconds=315360000"
- "traefik.frontend.headers.browserXSSFilter=true"
- "traefik.frontend.headers.contentTypeNosniff=true"
- "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.frontend.headers.SSLHost=${DOMAINNAME}"
- "traefik.frontend.headers.STSIncludeSubdomains=true"
- "traefik.frontend.headers.STSPreload=true"
- "traefik.frontend.headers.frameDeny=true"

# Traefik reverse proxy
traefik:
hostname: traefik
image: traefik:v1.7.18
container_name: traefik
restart: always
domainname: ${DOMAINNAME}
networks:
- default
- traefik_proxy
ports:
- "80:80"
- "443:443"
- "8080:8080"
environment:
- DUCKDNS_TOKEN=${DUCKDNS_TOKEN}
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.frontend.rule=Host:traefik.${DOMAINNAME}"
# - "traefik.frontend.rule=Host:${DOMAINNAME}; PathPrefixStrip: /traefik"
- "traefik.port=8080"
- "traefik.docker.network=traefik_proxy"
- "traefik.frontend.headers.SSLRedirect=true"
- "traefik.frontend.headers.STSSeconds=315360000"
- "traefik.frontend.headers.browserXSSFilter=true"
- "traefik.frontend.headers.contentTypeNosniff=true"
- "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.frontend.headers.SSLHost=${DOMAINNAME}"
- "traefik.frontend.headers.STSIncludeSubdomains=true"
- "traefik.frontend.headers.STSPreload=true"
- "traefik.frontend.headers.frameDeny=true"
- "traefik.frontend.auth.basic.users=${HTTP_USERNAME}:${HTTP_PASSWORD}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${USERDIR}/docker/traefik:/etc/traefik
- ${USERDIR}/docker/shared:/shared

#traefik networks block, to set up reverse proxy
networks:
traefik_proxy:
external:
name: traefik_proxy
default:
driver: bridge

和我的 traefik.toml

#debug = true

logLevel = "ERROR" #DEBUG, INFO, WARN, ERROR, FATAL, PANIC
InsecureSkipVerify = true
defaultEntryPoints = ["https", "http"]

# WEB interface of Traefik - it will show web page with overview of frontend an$
[api]
entryPoint = "traefik"
dashboard = true
address = ":8080"

# Force HTTPS
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

[file]
watch = true
filename = "/etc/traefik/rules.toml"

# Let's encrypt configuration
[acme]
email = "john.doe@notreal.com" #any email id will work
storage="/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging=true
onDemand = false #create certificate when container is created
[acme.dnsChallenge]
provider = "duckdns"
delayBeforeCheck = 300
[[acme.domains]]
main = "notmine.duckdns.org"
[[acme.domains]]
main = "*.notmine.duckdns.org"

# Connection to docker host system (docker.sock)
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "notmine.duckdns.org"
watch = true
# This will hide all docker containers that don't have explicitly
# set label to "enable"
exposedbydefault = false

以上是工作代码,我只是想不出如何进行调整而不破坏一切...

最佳答案

正如我所说,这很棘手,菜鸟,但可以通过向 rules.toml 添加另一个域并创建一个指向另一台服务器后端的前端来解决。我使用本指南来解决问题:docs.traefik.io/v1.5/configuration/backends/file

所以我不得不将我的“非 docker 服务器”作为需要证书的新域添加到 traefik.toml

# Domain for my server on the Raspberry
[[acme.domains]]
main = "eklandaresidenset.duckdns.org"

我还必须使用 key 编辑我的 acme.json 文件...当您重新启动 trefik 时,它应该会自行完成,但我从来没有做到这一点,所以我自己编辑了它并复制了我已经拥有的 key 在文件中。 :-)

然后我设置了我已经在 traefik.toml 中引用但尚未创建的 rules.toml,所以我这样做并添加了这个:

# Putting non-docker apps behind traefik proxy.
[backends]
[backends.backend-anotherserver]
[backends.backend-anotherserver.servers.anotherserver]
url = "http://xxx.xxx.xxx.xxx:yyy" #the other servers local IP and port
weight = 1

[frontends]
[frontends.frontend-anotherserver]
backend = "backend-anotherserver"
passHostHeader = true
passTLSCert = true
[frontends.frontend-anotherserver.routes.domain]
rule = "Host:anotherserver.duckdns.org" #created another server dns-subdirectory at duckdns.org pointing to the same IP as before... just to get another header!
[frontends.frontend-anotherserver.headers]
SSLRedirect = true
SSLHost = "anotherserver.duckdns.org"
STSSeconds = 315360000
STSIncludeSubdomains = true
STSPreload = true
forceSTSHeader = true
frameDeny = true
browserXSSFilter = true

问题解决了!

关于docker - 使用 traefik 将 ssl 路由到不同 docker 上的不同服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com