gpt4 book ai didi

docker-compose - Traefik v2.1.4 - 如何创建静态路由并重定向到特定主机和端口

转载 作者:行者123 更新时间:2023-12-03 17:01:13 29 4
gpt4 key购买 nike

我是 Traefik v2.1.4 的初学者。我在 docker 容器中使用。我正在尝试设置静态路由。我找到了一些使用 toml 配置文件的示例。

[providers]
[providers.file]
[http]
[http.routers]
[http.routers.netdata]
rule = "Host(`netdata.my-domain.com`)"
service = "netdata"
entrypoint=["http"]

[http.services]
[http.services.netdata.loadbalancer]
[[http.services.netdata.loadbalancer.servers]]
url = "https://192.168.0.2:19999"

按照这个例子,我想将它转换为我的 docker-compose 的 docker 标签。

我的 docker-compose 文件:
version: "3.7"
services:

traefik:
image: traefik:v2.1.4
container_name: traefik
restart: always
command:
- "--log.level=DEBUG"
- "--api.insecure=false"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.letsresolver.acme.tlschallenge=true"
- "--certificatesresolvers.letsresolver.acme.email=my-email@domain.com"
- "--certificatesresolvers.letsresolver.acme.storage=/letsencrypt/acme.json"
labels:
- "traefik.enable=true"
# middleware redirect
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
# global redirect to https
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.redirs.entrypoints=web"
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
# dashboard
- "traefik.http.routers.traefik.rule=Host(`traefik.my-domain.com`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.middlewares=admin"
- "traefik.http.routers.traefik.tls.certresolver=letsresolver"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.middlewares.admin.basicauth.users=user:hash-passwordXXX"

ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"


networks:
default:
external:
name: network

最佳答案

可以到 一起使用 2 个提供程序:filedocker .
您的 docker-compose.yml :

services:  traefik:    image: traefik:2.2.1    command: traefik --configFile=/etc/traefik/traefik.yml    ports:      - "80:80"      - "8080:8080"    volumes:      - ./traefik.yml:/etc/traefik/traefik.yml      - ./routes.yml:/etc/traefik/routes.yml      - /var/run/docker.sock:/var/run/docker.sock   # your services go here ...

Your traefik.yml:

api:
dashboard: true
insecure: true

entryPoints:
web:
address: :80

providers:
docker: {}

file:
filename: /etc/traefik/routes.yml
watch: true
您的 routes.yml :
http:
routers:
hello:
rule: PathPrefix(`/hello`)
service: hello@docker
rule: PathPrefix(`/world`)"
service: world@docker
这些只是示例,当然不要直接在生产环境中使用它们。

关于docker-compose - Traefik v2.1.4 - 如何创建静态路由并重定向到特定主机和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60420320/

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