如何在同一个https域url下使用traefik为两个提供商后端提供服务

时间:2018-12-18 13:04:47

标签: docker nginx traefik synology

[通过Siyu的有用评论,我可以解决问题,此外,我需要在标签中设置入口点-我已经添加了纠正的docker-compose.yaml,这是我所需要解决的全部内容]

目前,我已经重新配置了Synology工作站,以使用traefik处理https流量。

我想为traefik提供docker容器,并且仍然通过http(通过将traefik也用作SSL卸载程序)来提供synology工作站的Web界面。 Traefik现在遇到了处理两个 provider 后端的问题,一个后端是“原始” synology Web服务器,另一个是来去去的docker容器。 当前设置可用于提供“ test.com”(Synology DSM Web界面)。但是,如果尝试使用“ / dashboard”访问容器,它只会给我一个404。

如何进行设置,以便为两个后端(docker + docker外的webserver)提供服务?

数据点

  • 识别docker接口并
  • 从traefik中读取标签(*参见下文)(可以在日志中看到)
  • synology nginx在docker的外部之外运行(不作为容器!)
  • 整个synology工作站都在IPv4 / IPv6环境(两者)中提供服务
  • Synology nginx已被修改,不能在标准的http / https端口上使用(如我在nginx的配置中所见,它仅重定向到端口5000/5001)

应提供的预期设置

请注意,原始的语法是一个涵盖所有域(/ *)

+-----------------------------------------------------------------------
| Synology Workstation                                                
|                                                                     
|           +--------------------------------------------------------+
|           |  Docker                                                | 
|           |           +---------+          +-------------------+   |
|-->HTTPS-->|-->HTTPS-->| Traefik |-->HTTP-->| test.com/dashboard|   |
| 443:443   |           |         |          |                   |   |
|           |           +---------+--+       +-------------------+   |
|           |                |       |                               |
|           |                |       |         +------------------+  |
|           |                |       +--HTTP-->| test.com/stats   |  |
|           |                |                 +-------------------  |
|           |                |                                       |
|           +----------------|----------------------------------------
|                            |         +-------------------+
|                            +--HTTP-->|test.com/*         |
|                                      |(nginx of synology)|
|                                      +-------------------+
+--------------------------------------------------------------------

traefik.toml看起来像这样:

debug=true
logLevel="DEBUG"

[traefikLog]
filePath = "/etc/traefik/traefik.log"

[accessLog]
filePath = "/etc/traefik/access.log"

defaultEntryPoints = ["http", "https"]

[entryPoints]

[entryPoints.http]
address    = ":80"
[entryPoints.http.redirect]
entryPoint = "https"

[entryPoints.https]
address    = ":443"

[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile   = "/etc/pki/tls/certs/test.com.crt"
keyFile    = "/etc/pki/tls/private/test.com.key"

[backends]
[backends.wbackend]
[backends.wbackend.servers.server]
url        = "http://workstation.test.com:5000"
#weight     = 10

[frontends]
[frontends.workstation]
backend        = "wbackend"
passHostHeader = true
entrypoints    = ["https"]
[frontends.workstation.routes.route1]
rule       = "Host:workstation.test.com"

# You MUST ADD file otherwise traefik does not parse the  fronted rules
[file]

[docker]
endpoint    = "unix:///var/run/docker.sock"

Docker组成的代码段(请参阅映射域的标签)。

---
version: '2'


services:
  traefik:
    # Check latest version: https://hub.docker.com/r/library/traefik/tags/
    image:          traefik:1.7.6
    restart:        unless-stopped
    container_name: traefik
    mem_limit:      300m
    #network_mode:   host

    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /volume1/container/traefik/etc/pki/tls/certs/workstation.test.com.crt:/etc/pki/tls/certs/workstation.test.com.crt
    - /volume1/container/traefik/etc/pki/tls/private/workstation.test.com.key:/etc/pki/tls/private/workstation.test.com.key
    - /volume1/container/traefik/etc/traefik:/etc/traefik

    ports:
    - "80:80"
    - "443:443"

    labels:
    - traefik.stat.frontend.rule=Host:workstation.test.com;Path:/dashboard
    - traefik.stat.backend=traefik
    - traefik.stat.frontend.entryPoints=https
    - traefik.stat.frontend.rule=Host:workstation.test.com;PathPrefixStrip:/dashboard
    - traefik.stat.port=8080

1 个答案:

答案 0 :(得分:2)

您的配置存在一些问题:

  • 您的toml没有传入
  • 未启用api
  • 缺少标签后端
  • 应使用PathPrefixStrip

尝试

volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /path/to/traefik.toml:/etc/traefik/traefik.toml
command: --api 
ports:
- "80:80"
- "443:443"
- "8080:8080" // help you debug
labels:
- traefik.backend=traefik
- "traefik.frontend.rule=PathPrefixStrip:/dashboard/;Host:test.io"
- traefik.port=8080