添加 /etc/traefik/traefik.toml 配置文件

traefik会在/etc/traefik 、 $HOME/.traefik/ 或 当前目录查找 traefik.toml 文件。
所以本文的配置文件都放/etc/traefik下面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
logLevel = "WARN"
# 同时支持http和https
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

# 配置自动Let's Encrypt证书
[acme]
email = "yourname@mail.com"
storage = "/etc/traefik/acme.json"
entryPoint = "https"
onDemand = true

# 开启日志功能
[accessLog]
filePath = "/var/log/traefik/acceslog.txt"

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

# 开启web管理端
[web]
address = ":8080"
readOnly = true
[web.auth.basic]
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"] #test/test 登陆名/密码 可用openssl生成

# 使用文件方式
[file]
directory = "/etc/traefik/rules" # 在指定目录查找配置文件
watch = true

示例:traefik后台配置域名访问

编辑/etc/traefik/rules/traefikadmin.toml文件

1
2
3
4
5
6
7
8
9
10
11
[backends]
[backends.traefikadmin]
[backends.traefikadmin.servers.server1]
url = "http://localhost:8080"
weight = 10

[frontends]
[frontends.traefikadmin]
backend = "traefikadmin"
[frontends.traefikadmin.routes.rule_1]
rule = "Host:traefik.ystyle.top"

示例:syncthing配置域名访问

编辑/etc/traefik/rules/syncthing.toml文件

1
2
3
4
5
6
7
8
9
10
11
[backends]
[backends.syncthing]
[backends.syncthing.servers.server1]
url = "http://localhost:8384"
weight = 10

[frontends]
[frontends.syncthing]
backend = "syncthing"
[frontends.syncthing.routes.rule_1]
rule = "Host:syncthing.ystyle.top"