9951 explained code solutions for 126 technologies


nginx-luaHow to use Luarocks and other modules in Nginx Lua


After installation of Luarocks module, we need to add its include path into Nginx Lua environment:

lua_package_path "/usr/local/share/lua/5.3/?.lua;";

init_by_lua_block {
  uuid = require("uuid")
}

server {
  location / {
    content_by_lua_block {
      local id = uuid()
    }
  }
}ctrl + c
lua_package_path

specify include path for Lua modules

/usr/local/share/lua/5.3/

possible path to Luarocks installed modules (find your own path)

init_by_lua_block

nginx-lua module directive to run specified Lua code on server startup

require("uuid")

loads UUID Luarocks module

content_by_lua_block

nginx-lua module directive to specify block of Lua code

local id = uuid()

UUID module sample usage