Traefix v1.7静态证书和动态acme证书

时间:2020-06-18 05:54:17

标签: docker-compose lets-encrypt traefik acme

我正在以群体模式在docker中使用 traefik:1.7.6-alpine 。我需要指定静态ssl证书和其他自我管理的acme证书。

这是我提起容器时遇到的错误:

time="2020-06-18T02:45:52Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/basics/#collected-data\n"
time="2020-06-18T02:45:52Z" level=error msg="Failed to read new account, ACME data conversion is not available : unexpected end of JSON input"
time="2020-06-18T02:45:52Z" level=error msg="Unable to add ACME provider to the providers list: unable to get ACME account : unexpected end of JSON input"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server https &{Address::443 TLS:0xc000288630 Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a45c0} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server traefik &{Address::8080 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a4560} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :443"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server http &{Address::80 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a4580} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Starting provider configuration.ProviderAggregator {}"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :8080"
time="2020-06-18T02:45:52Z" level=info msg="Starting provider *docker.Provider {\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Trace\":false,\"TemplateVersion\":2,\"DebugLogGeneratedTemplate\":false,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"arkaangel.com\",\"TLS\":null,\"ExposedByDefault\":false,\"UseBindPortIP\":false,\"SwarmMode\":false,\"Network\":\"\",\"SwarmModeRefreshSeconds\":15}"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :80"

这是我的traefik.toml

debug = true
logLevel = "INFO"
defaultEntryPoints = ["http", "https"]
[entryPoints]
    [entryPoints.http]
        address = ":80"
    [entryPoints.https]
        address = ":443"
        [entryPoints.https.tls]
            [[entryPoints.https.tls.certificates]]
                certFile = "/path/to/first/first.crt"
                keyFile = "/path/to/first/first.key"
            [[entryPoints.https.tls.certificates]]
                certFile = "/path/to/second/second.crt"
                keyFile =  "/path/to/second/second.key"
[api]
  dashboard = true
  [api.statistics]
    recentErrors = 10
[docker]
  exposedbydefault = false
  watch = true
  domain = "mydomain.com"

[acme]
email = "myemail@gmail.com"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging = true
onHostRule = true
    [acme.httpChallenge]
       entryPoint = "http"
    [[acme.domains]]
       main = "third-site.com"

这是我将acme.json文件挂载到docker-compose中以保持生成的证书的方式:

volumes:
./traefik/acme/acme.json:/etc/traefik/acme/acme.json

acme.json 文件具有 600 权限,所有者为 root:root

除了显示的配置,我尝试了一些无法生成证书的事情:

  1. 不是映射 acme.json 文件,而是映射父文件夹,以便traefik创建 acme.json 文件(失败)
  2. 请勿映射 acme.json 的任何卷,以便在删除容器时丢失该卷。 (失败)
  3. 将所有者更改为文件 acme.json myuser:myuser ,因此从容器中,用户 1000 显示为所有者< strong>(失败)

1 个答案:

答案 0 :(得分:1)

我能够解决以下错误的方法:“在文件内写入”“无法读取新帐户,ACME数据转换不可用:JSON输入意外结束” acme.json {},显然是在尝试读取一个空文件并将其解析为json时出现错误。

摘要: 在要映射的主机上创建 acme.json 时,您必须执行以下操作:

touch acme.json
echo '{}'> acme.json
chmod 600 acme.json