安装配置
在使用 CLI 命令配置 Traefik 之后,你可能需要对其进行更细致的配置。CLI 提供了一种迅速启动和测试 Traefik 的方法,但对于生产环境或需要更复杂配置的场景,推荐使用配置文件。配置文件不仅可以提供更多的配置选项,还可以在重启服务时保持配置不变,便于管理和版本控制。
Last updated
traefik --providers.file.directory=/home/config --api.dashboard=true --api.insecure./traefik --configFile=your-config-file.yamlglobal:
checkNewVersion: false # 周期性的检查是否有新版本发布
sendAnonymousUsage: false # 周期性的匿名发送使用统计信息
serversTransport:
insecureSkipVerify: true # Traefik忽略验证代理服务的TLS证书
#从文件获取
providers:
file:
directory: /home/my-traefik/config
watch: true
ping: true #开启ping
#api
api:
dashboard: true #dashboard-ui
insecure: true
debug: false
#配置指标
metrics:
prometheus: # 配置Prometheus监控指标数据,并使用默认配置
addRoutersLabels: true # 添加routers metrics
entryPoint: "metrics" # 指定metrics监听地址
entryPoints:
metrics:
address: ":19100" # 配置19100端口,作为metrics收集入口
http:
address: ":80" #配置80作为http入口
# http请求自动跳转https
http:
redirections:
entryPoint:
to: https
proxyProtocol:
insecure: true
forwardedHeaders:
insecure: true
https:
address: ":443" # 配置443端口,并设置入口名称为 websecure
proxyProtocol:
insecure: true
forwardedHeaders:
insecure: true
# 开启ACME 自动生成HTTPS证书
certificatesResolvers:
myCertResolver:
acme:
# 邮箱地址
email: "2694484453@qq.com"
# 签发的https证书存放位置
storage: "/home/my-traefik/acme.json"
# 自动签发证书的一种验证方式(还有tlsChallent、dnsChallenge,我们用的是常用的这种httpChallenge方式)
httpChallenge:
entryPoint: http
accessLog:
filePath: "/home/my-traefik/logs/access.log" # 设置访问日志文件存储路径,如果为空则输出到控制台
format: "common" # 设置访问调试日志格式
bufferingSize: 0 # 设置访问日志缓存行数
filters:
statusCodes: [ "200","500","404","403","502" ] # 设置只保留指定状态码范围内的访问日志
retryAttempts: true # 设置代理访问重试失败时,保留访问日志
minDuration: 20 # 设置保留请求时间超过指定持续时间的访问日志
fields: # 设置访问日志中的字段是否保留(keep保留、drop不保留)
defaultMode: keep # 设置默认保留访问日志字段
names: # 针对访问日志特别字段特别配置保留模式
ClientUsername: drop
StartUTC: drop # 禁用日志timestamp使用UTC
headers: # 设置Header中字段是否保留
defaultMode: keep # 设置默认保留Header中字段
names: # 针对Header中特别字段特别配置保留模式
#User-Agent: redact # 可以针对指定agent
Authorization: drop
Content-Type: keep
nohup traefik --providers.file.directory=/home/config --api.dashboard=true --api.insecure > treafik-log.txt 2>&1 &nohup traefik --configFile=/home/my-traefik/traefik.yml > /dev/null 2>&1 &