从Noob到Traefik和Docker。我已经使用以下方法准备了自签名证书:
openssl req -x509 -newkey rsa:4096 -keyout www.example.co.uk.key -out www.example.co.uk.crt-days 365
在我的traefik.toml文件中:
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "certs/www.example.co.uk.crt"
keyFile = "certs/www.example.co.uk.key"
但这会导致:
traefik | time="2019-06-17T22:11:17Z" level=debug msg="Serving default cert for request: \"www.example.co.uk\""
traefik | time="2019-06-17T22:11:17Z" level=debug msg="http: TLS handshake error from 172.20.0.1:57770: tls: no certificates configured"
如果我省略证书定义,那么traefik.toml读为:
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
# [[entryPoints.https.tls.certificates]]
# certFile = "certs/www.example.co.uk.crt"
# keyFile = "certs/www.example.co.uk.key"
我获得了Traefik提供的虚拟证书,效果很好,但我只是想绕开为什么不使用定义的证书的原因。
在我的docker-compose.yml中,我相信我已经安装了正确的卷:
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
- ./traefik.toml:/traefik.toml
- /var/www/docker/certs:/certs
相对于我的certs/
l和docker-compose.ym
文件,证书位于traefik.toml
。 root用户拥有的权限似乎也不错-crt
具有644,而key
具有600。
如何使用自签名证书代替Traefiks的默认值?
答案 0 :(得分:1)
可能是路径不匹配,尤其是某些相对路径和其他绝对路径。在撰写文件中尝试以下操作(本地证书的相对路径):
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/traefik.toml
- ./certs:/certs
然后在toml中切换到绝对路径(证书上的斜杠):
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/certs/www.example.co.uk.crt"
keyFile = "/certs/www.example.co.uk.key"