OpenResty auto_ssl 太长 lua 代码块错误

OpenResty auto_ssl too long lua code block error

我正在使用 OpenResty with nginx to auto-obtain SSL certs from Let's Encrypt。有一个 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)

我是否需要提前定义这个字符串,或者在某处指定它的长度?

EDIT 好的,所以我正在考虑另一种方式。如果我尝试这个,有人会看到问题吗?任何类型的性能问题,或 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)

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