Lua-resty-auto-ssl: allow_domain 调用频率

创建于 2017-10-06  ·  6评论  ·  资料来源: auto-ssl/lua-resty-auto-ssl

我们已经实现了一个 Web 服务来进行域验证。 我们好奇的是在allow_domain方法中发出 Web 请求对性能的影响? 还有这种方法多久被调用一次? 它是否仅在 Let's Encrypt 序列之前调用?

如果存储中的域有证书,我们似乎不需要调用allow_domain

也许在文档中多一点这种类型的解释会很有用。

谢谢你。

所有6条评论

无论您是否有证书,它都会被调用。 就我个人而言,在询问我们的后端是否可以生成新证书之前,我会检查我们是否已经拥有证书。

-- first check if we have the certificate already, else check with backend if we allow it 
    local certstorage = auto_ssl:get("storage")

    local fullchain_pem, privkey_pem = certstorage:get_cert(domain)
    if fullchain_pem then
      return true
    else ...

我也有点担心开销/性能影响,但仍处于计划阶段,到目前为止还没有。

@brianlund感谢分享。 我已经实现了一个本地lua_shared_dict来“缓存”来自上述 Web 服务的结果。

    auto_ssl:set("allow_domain", function(domain)
      local http = require "resty.http"
      local httpc = http.new()
      local cjson = require "cjson"
      local our_allow_domain_cache = ngx.shared.our_allow_domain_cache

      local found = our_allow_domain_cache:get(domain)

      if found == nil then
        local res, err = httpc:request_uri("[is domain allowed web service]"..domain, {
          method = "GET",
        })

        if not res then
          found = false
        else
          local data = cjson.decode(res.body)
          found = data.found
        end

        -- Cache for 60 seconds, for now...
        our_allow_domain_cache:set(domain, found, 60)
      else
        if found then
          -- Known good domain, keep it in cache for a little longer
          our_allow_domain_cache:set(domain, found, 300)
        end
      end

我真的很喜欢你检查auto_ssl:get("storage")服务的想法。 我可能会选择类似的东西。 我们可以假设每个请求都会发生这种情况吗? 还是lua_shared_dict auto_ssl被用作存储缓存层? 看起来可能是: https :

我想知道在您的示例中检查是否会更好:
ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain) vs 直接调用storage

我相信ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain)只检查共享内存缓存。 我计划运行多个节点,因此需要在它们之间共享一些东西(redis 存储)。 不过,我喜欢你的缓存解决方案,它会节省大量对存储服务的调用,如果我发现频繁调用它有任何问题,我会记住这一点。

我想感谢@jasonbouffard在那里提供的演示代码 - 这对我来说是一个非常有用的构建块! 欣赏它!

我们可以假设每个请求都会发生这种情况吗?

这是一个很好的问题。

我的假设是当域没有证书时会调用此方法,但我不确定。
您是否能够确认@jasonbouffard

@阿里尔3z4

我也对这个很好奇。
文档对此并不那么透明,所以我不得不检查源代码。

因此,对于每个请求,auto-ssl 都会执行以下操作:

  • 尝试从ngx.shared.auto_ssl字典中获取证书,这些字典缓存了 1 小时
  • 调用用户定义的allow_domain方法
  • 尝试从存储中获取证书
  • 创建新证书

在 README.md 中解释这一点会很完美。
谢谢!

来源:

https://github.com/auto-ssl/lua-resty-auto-ssl/blob/86d3c94807ad1585b464fad2d4defb379f9c152a/lib/resty/auto-ssl/ssl_certificate.lua#L104 -L157

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

ronaldgetz picture ronaldgetz  ·  10评论

brendon picture brendon  ·  9评论

jmvbxx picture jmvbxx  ·  6评论

domharrington picture domharrington  ·  7评论

discobean picture discobean  ·  8评论