Nginx Lua Plugin

Lua can be used inside an NGINX config file to provide dynamic programming support.

Assumptions:

  • Ubuntu 20.04
  • Nginx 1.18
sudo apt install lua-nginx-cookie libnginx-mod-http-ndk libnginx-mod-http-lua -y

As a short example, this is a short Lua rewrite block accessing a cookie named ACookie and retrieving a substring.

set $substring "";
set $tempcode "";

rewrite_by_lua_block {
        ngx.var.tempcode = ngx.unescape_uri(ngx.var.cookie_ACookie)
        ngx.var.substring = string.sub(ngx.var.tempcode, 5, 10)
}

References