Lua-resty-auto-ssl: ์—…๊ทธ๋ ˆ์ด๋“œ ๊ฐ€์ด๋“œ

์— ๋งŒ๋“  2019๋…„ 07์›” 01์ผ  ยท  11์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: auto-ssl/lua-resty-auto-ssl

์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์—…๊ทธ๋ ˆ์ด๋“œ ๊ฐ€์ด๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ?

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

@bryanus ์ด ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค:

init_by_lua_block {
    auto_ssl = (require "resty.auto-ssl").new()
    auto_ssl:set("allow_domain", function(domain)

    -- reading from domains.txt and in testing

    local shell_execute = require "resty.auto-ssl.utils.shell_execute"
    local ngx_re = require "ngx.re"
    local result, err = shell_execute({"cat", "/home/user/domains.txt"})

    if err then
      ngx.log(ngx.ERR, "allow_domain cat error: ", err)
    else
      local domains = ngx_re.split(result["output"], "\n")
      for _, d in ipairs(domains) do
        if (domain == d) then
          return true
        end
      end
    end

    return false

    end)
    auto_ssl:set("renew_check_interval", 43200)
    auto_ssl:init()
  }

์„ค๋ช…:

์ปค๋ฐ‹ https://github.com/GUI/lua-resty-auto-ssl/commit/59758847b44981edfaf484d3a981deea82409332 lua-resty-auto-ssl์šฉ https://github.com/GUI/lua-shell-games ์˜ ์ƒˆ ๋ฒ„์ „ ๊ตฌํ˜„ ์—ฌ๊ธฐ.

์š”์•ฝํ•˜์ž๋ฉด shell_execute() ํ•จ์ˆ˜์˜ API๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค(๋งค๊ฐœ๋ณ€์ˆ˜ ๋ฐ ๋ฐ˜ํ™˜๊ฐ’).

๊ฐœ์ธ์ ์œผ๋กœ Nginx์—์„œ Lua ์ฝ”๋“œ๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š” ๊ฒƒ์€ ์•…๋ชฝ์ž…๋‹ˆ๋‹ค. ์•„๋งˆ๋„ ์–ธ์  ๊ฐ€๋Š” ๋” ์‰ฌ์šธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ชจ๋“  11 ๋Œ“๊ธ€

0.12.0์—์„œ 0.13.1๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ •๋ณด์—๋„ ๊ด€์‹ฌ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

sudo luarocks install lua-resty-auto-ssl ์„ ์‹คํ–‰ํ•˜๋ฉด ํ˜„์žฌ 0.12.0 ๊ตฌ์„ฑ/์„ค์ •์ด ์ง€์›Œ์ง€๋‚˜์š”?

์•„๋‹ˆ๋ฉด @ronaldgetz ๊ฐ€ ์ œ๊ณต ํ•œ ๋Œ€๋กœ ํƒˆ์ˆ˜๋œ ํŒŒ์ผ์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์ด ๋” ์•ˆ์ „ํ•ฉ๋‹ˆ๊นŒ?

ํ‹ฐ์•„.

12์—์„œ 13.1๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค sudo luarocks install lua-resty-auto-ssl ๋งŒํผ ๊ฐ„๋‹จํ•˜๊ณ  $ sudo systemctl restart openresty ๋กœ openresty๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. :)

@aviatrix ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋”ฐ๋ผ์„œ nginx ๊ตฌ์„ฑ ๋˜๋Š” ๊ธฐํƒ€ ํ•ญ๋ชฉ์„ ๋ฎ์–ด์“ฐ์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด? ๋‚˜๋Š” ๋‚ด ์•ˆ์—์„œ ๋งŽ์€ ์ผ์ด ์ผ์–ด๋‚˜๊ณ  ์žˆ๋‹ค.

๋ฐฉ๊ธˆ ์ƒˆ ๋„๋ฉ”์ธ ๋ฐœ๊ธ‰์„ ํ…Œ์ŠคํŠธํ–ˆ์œผ๋ฉฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ ์ด ๋ฌธ์ œ๊ฐ€ ์ˆ˜์ •๋˜๊ฑฐ๋‚˜ ์˜ํ–ฅ์„ ๋ฐ›๋Š”์ง€ ์™„์ „ํžˆ ํ™•์‹คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜๋„ ์—…๊ทธ๋ ˆ์ด๋“œ๋Š” ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ...

@bryanus ๋Š” ๋ฌด์—‡์ด๋“  ํ•˜๊ธฐ ์ „์— ํ•ญ์ƒ ๋ฐฑ์—…์„ ํ•ฉ๋‹ˆ๋‹ค! ๋‚˜๋Š” ์ด๊ฒƒ์„ ์–ด๋ ต๊ฒŒ ๋ฐฐ์› ๋‹ค.
๊ตฌ์„ฑ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๊ฐœ์ธ ์ €์žฅ์†Œ์˜ ๋ฒ„์ „ ์ œ์–ด์— ๋ณด๊ด€ํ•˜๊ณ  ๋งŒ์ผ์„ ๋Œ€๋น„ํ•˜์—ฌ ๋ฏธ๋ฆฌ conf ํด๋”๋ฅผ cpํ•˜์‹ญ์‹œ์˜ค.

์ด ์—…๋ฐ์ดํŠธ( 13.1)๋Š” Let's Encrypt ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์ข…์†์„ฑ Dehydrated ์„ ์—…๋ฐ์ดํŠธํ•˜์—ฌ Let's Encrypt์˜ v1 ACME ํ”„๋กœํ† ์ฝœ ์‚ฌ์šฉ ์ค‘๋‹จ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ์—…๋ฐ์ดํŠธํ•˜์ง€ ์•Š์œผ๋ฉด ํ•œ ๋‹ฌ ์ •๋„ ํ›„์— ์ƒˆ ์ธ์ฆ์„œ๋ฅผ ์–ป์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

@aviatrix ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ํ•ด๋ณด๊ณ  ์—ฌ๊ธฐ์— ๋‹ค์‹œ ๋ณด๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ตฐ์š”. ์—…๊ทธ๋ ˆ์ด๋“œ/์„ค์น˜ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ณ  openresty๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜์ž ์ฆ‰์‹œ ์„ค์ •์ด ์ค‘๋‹จ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

2019/11/08 21:06:23 [error] 2973#2973: *113 [lua] ssl_certificate.lua:310: ssl_certificate(): auto-ssl: failed to run do_ssl: /usr/local/openresty/luajit/share/lua/5.1/shell-games.lua:233: bad argument #1 (table expected, got string), context: ssl_certificate_by_lua*, client: 103.3.244.23, server: 0.0.0.0:443

์šด ์ข‹๊ฒŒ๋„ ์ด๊ฒƒ์€ ์Šคํ…Œ์ด์ง• ์„œ๋ฒ„์— ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ ์ด ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. @aviatrix์— ๋Œ€ํ•œ ์•„์ด๋””์–ด๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ? ๋ผ์ธ ํŽธ์ง‘ ์„ ํŒจ์น˜ํ•˜๊ณ  ๊ณ„์† ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

์—…๋ฐ์ดํŠธ: ๊ทธ๋ž˜์„œ ์ง€๊ธˆ์€ ๋‹จ์ˆœํžˆ @ronaldgetz ํŒจ์น˜๋กœ ํƒˆ์ˆ˜๋œ ํŒŒ์ผ์„ ์ง์ ‘ ํŽธ์ง‘ํ–ˆ๊ณ  ๋ชจ๋“  ๊ฒƒ์ด openresty๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•œ ํ›„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ์ „์ฒด ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜๋ฅผ ํŒŒ์•…ํ•˜๊ณ  ํŒŒ์•…ํ•˜๋Š” ๋™์•ˆ ์ž ์‹œ ๊ธฐ๋‹ค๋ ค์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ํŒจ์น˜๊ฐ€ "์ถฉ๋ถ„ํžˆ" ์ข‹๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.

@bryanus ๋„๋ฉ”์ธ ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ์— ์‚ฌ์šฉ์ž ์ •์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ์ด ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜๋Š” lua-resty-auto-ssl์˜ ์ตœ์‹  ๋ฆด๋ฆฌ์Šค๊ฐ€ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์‰˜ ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(์˜ˆ: ์‚ฌ์šฉ์ž ์ •์˜ ํ…์ŠคํŠธ ํŒŒ์ผ์„ ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ๋กœ ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด cat ๋ช…๋ น์„ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ). ์ด์ œ ์‰˜ ์ธ์ˆ˜๋Š” ์ด์ „์— ๋ฌธ์ž์—ด ๋Œ€์‹  ํ…Œ์ด๋ธ”์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ•œ ๋ฒˆ์˜ ๋ฐฐํฌ์—์„œ๋„ ๊ทธ ๋ฌธ์ œ๋ฅผ ๋ณด์•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ฌด๋ฐ๋„ ์ถ”์ธกํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

@andreasschroth ์™€์šฐ! ๊ทธ๊ฒƒ์ด ๋ฐ”๋กœ ๋‚ด๊ฐ€ ํ•˜๊ณ  ์žˆ๋Š” ์ผ์ž…๋‹ˆ๋‹ค! ๋‚ด ๊ตฌ์„ฑ์˜ ์˜์›ํ•œ ํ…์ŠคํŠธ ํŒŒ์ผ์—์„œ ๋„๋ฉ”์ธ์„ ํ—ˆ์šฉ ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

````
init_by_lua_block {
auto_ssl = ("resty.auto-ssl" ํ•„์š”).new()
auto_ ssl:set ("allow_domain", ํ•จ์ˆ˜(๋„๋ฉ”์ธ)

-- reading from domains.txt and in testing

local shell_execute = require "resty.auto-ssl.utils.shell_execute"
local ngx_re = require "ngx.re"
local status, output, err = shell_execute("cat /home/user/domains.txt")

if err then
  ngx.log(ngx.ERR, "allow_domain cat error: ", err)
else
  local domains = ngx_re.split(output, "\n")
  for _, d in ipairs(domains) do
    if (domain == d) then
      return true
    end
  end
end

return false

end)
auto_ssl:set("renew_check_interval", 43200)
auto_ssl:init()

}
````

๊ฐ™์€ ์ผ์„ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๊นŒ? ๋‚ด ์…ธ ๋ช…๋ น์„ ํ…Œ์ด๋ธ”๋กœ ์ „๋‹ฌํ•˜๋„๋ก ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•ฝ๊ฐ„ ํ˜ผ๋ž€์Šค๋Ÿฝ์Šต๋‹ˆ๋‹ค. ์ด์— ๋Œ€ํ•œ ๋ฌธ์„œ๋ฅผ ๋” ํŒŒํ—ค์ณ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•˜์…จ๋‚˜์š”? ์ด ํŒ์„ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

@bryanus ์ด ์ฝ”๋“œ๋ฅผ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค:

init_by_lua_block {
    auto_ssl = (require "resty.auto-ssl").new()
    auto_ssl:set("allow_domain", function(domain)

    -- reading from domains.txt and in testing

    local shell_execute = require "resty.auto-ssl.utils.shell_execute"
    local ngx_re = require "ngx.re"
    local result, err = shell_execute({"cat", "/home/user/domains.txt"})

    if err then
      ngx.log(ngx.ERR, "allow_domain cat error: ", err)
    else
      local domains = ngx_re.split(result["output"], "\n")
      for _, d in ipairs(domains) do
        if (domain == d) then
          return true
        end
      end
    end

    return false

    end)
    auto_ssl:set("renew_check_interval", 43200)
    auto_ssl:init()
  }

์„ค๋ช…:

์ปค๋ฐ‹ https://github.com/GUI/lua-resty-auto-ssl/commit/59758847b44981edfaf484d3a981deea82409332 lua-resty-auto-ssl์šฉ https://github.com/GUI/lua-shell-games ์˜ ์ƒˆ ๋ฒ„์ „ ๊ตฌํ˜„ ์—ฌ๊ธฐ.

์š”์•ฝํ•˜์ž๋ฉด shell_execute() ํ•จ์ˆ˜์˜ API๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค(๋งค๊ฐœ๋ณ€์ˆ˜ ๋ฐ ๋ฐ˜ํ™˜๊ฐ’).

๊ฐœ์ธ์ ์œผ๋กœ Nginx์—์„œ Lua ์ฝ”๋“œ๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š” ๊ฒƒ์€ ์•…๋ชฝ์ž…๋‹ˆ๋‹ค. ์•„๋งˆ๋„ ์–ธ์  ๊ฐ€๋Š” ๋” ์‰ฌ์šธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@andreasschroth ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” lua-resty-shell ๋ชจ๋“ˆ์˜ ๊ตฌ๋ฌธ์„ ๊ฒ€ํ† ํ•˜๊ณ  ์žˆ์—ˆ๊ณ  ๋ณ€๊ฒฝ์ด ๊ทธ๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์‹œ๊ฐ„์„ ๋‚ด์–ด ๋„์™€์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. (์•„๋งˆ๋„ ๋‚ด์ผ) ์‹œ๋„ํ•ด ๋ณด๊ณ  ๋‹ค์‹œ ๋ณด๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

ํšจ๊ณผ๊ฐ€์žˆ๋‹ค! ๋„์›€์„ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค @andreasschroth. ๋‚ด ์กฐ๊ฑด๋ถ€ ์ถœ๋ ฅ๋„ ์ˆ˜์ •ํ–ˆ๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ชฐ๋ž์Šต๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ์ฒ˜์Œ ์ƒ๊ฐํ–ˆ๋˜ ๊ฒƒ๋ณด๋‹ค ๋” ๋งŽ์ด ์ฐธ์—ฌํ–ˆ๋‹ค. ์˜ˆ, nginx ๊ตฌ์„ฑ์—์„œ Lua๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š” ๊ฒƒ์€ ๊ณ ํ†ต์Šค๋Ÿฝ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํฐ ๋„์›€์ด ๋œ๋‹ค๋ฉด ๊ทธ๋ ‡๊ฒŒ ๋‚˜์˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค! ๊ฑด๋ฐฐ! ;-)

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰