【问题标题】:OpenResty auto_ssl too long lua code block errorOpenResty auto_ssl too long lua 代码块错误
【发布时间】:2018-03-13 02:15:52
【问题描述】:

我正在使用 OpenResty 和 nginx 从 Let's Encrypt 自动获取 SSL 证书。有一个 lua 函数,您可以在其中允许某些域。在这个函数中,我有一个正则表达式来将我的域列入白名单。添加一定数量(不确定确切数量)后,我开始收到此错误:

nginx: [emerg] too long lua code block, probably missing terminating characters in /usr/local/openresty/nginx/conf/nginx.conf:60. 

缩小该字符串会使错误消失。

我不熟悉 lua,但这里是示例代码。我这里有几百个域要添加。

auto_ssl:set("allow_domain", function(domain)
  return ngx.re.match(domain, "^(domain1.com|domain2.com|domain3.com....)$", "ijo")
end)

我需要提前定义这个字符串,还是在某个地方指定它的长度?

编辑好的,所以我正在考虑另一种方式。如果我尝试这个,有人会发现问题吗?任何类型的性能问题,或与 lua 相关的事情?也许有更有效的方法来做到这一点?

auto_ssl:set("allow_domain", function(domain)
  domains = [[
    domain1.com
    domain2.com
    domain3.com
    -- continues up to domain300.com
  ]]
  i, j = string.find(domains, domain)
  return i ~= nil
end)

【问题讨论】:

  • 您好,您最终得到的解决方案是什么?如果你加载了一个外部文件,你是怎么调用它的? TIA。
  • 我最终使用了带有return ngx.re.match(domain, "^(domain1.com|domain2.com)$", "ijo")的正则表达式

标签: nginx lua lets-encrypt openresty


【解决方案1】:

OpenResty 允许通过文件加载更复杂的 lua 代码。 https://github.com/openresty/lua-nginx-module#init_by_lua_file 这只是一个指令。有多种方法可以加载 lua 代码。这种方式对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2017-10-27
    • 1970-01-01
    • 2020-04-07
    • 2020-07-31
    相关资源
    最近更新 更多