我试图让 Traefik 为所有具有匹配主机规则的路由器使用手动配置的通配符证书。我认为 Traefik 会尝试根据主机规则中使用的域查找证书,但它始终使用默认生成的证书。
traefik.yml
global:
checkNewVersion: false
sendAnonymousUsage: false
log:
level: DEBUG
entryPoints:
web:
address: ":80"
web-secure:
address: ":443"
providers:
file:
directory: /etc/traefik/conf
watch: true
Run Code Online (Sandbox Code Playgroud)
动态配置:
http:
routers:
test:
rule: "Host(`subdomain.wildcard.domain.tld`)"
entryPoints: ["web"]
service: service-test
middlewares: ["https_redirect"]
test-secure:
rule: "Host(`subdomain.wildcard.domain.tld`)"
entryPoints: ["web-secure"]
service: service-test
tls: {}
services:
service-test:
loadBalancer:
servers:
- url: "http://helloworld"
middlewares:
https_redirect:
redirectScheme:
scheme: https
permanent: true
Run Code Online (Sandbox Code Playgroud)
Traefik 在 Docker 容器内运行,基于它可以看到的日志并使用挂载的证书文件:
time="2020-03-04T10:44:13Z" level=debug msg="No store is defined to add the certificate <...>, it will be added to the default store."
time="2020-03-04T10:44:13Z" level=debug msg="Adding certificate for domain(s) wildcard.domain.tld,*.wildcard.domain.tld"
time="2020-03-04T10:44:13Z" level=debug msg="No default certificate, generating one"
Run Code Online (Sandbox Code Playgroud)
但是,在执行 curl 请求时,将使用默认证书:
curl -k -v --header "Host: subdomain.wildcard.domain.tld" https://192.168.173.143/
* Server certificate:
* subject: CN=TRAEFIK DEFAULT CERT
* start date: Mar 4 10:44:13 2020 GMT
* expire date: Mar 4 10:44:13 2021 GMT
* issuer: CN=TRAEFIK DEFAULT CERT
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
Run Code Online (Sandbox Code Playgroud)
当将证书指定为默认证书时,Traefik 确实使用了它,这使得在尝试将路由器与合适的证书匹配时出现问题的情况更加明显。
tls:
certificates:
- certFile: /ssl/wildcard.crt
keyFile: /ssl/wildcard.key
stores:
default:
defaultCertificate:
certFile: /ssl/wildcard.crt
keyFile: /ssl/wildcard.key
Run Code Online (Sandbox Code Playgroud)