Working with multiple Lua scripts in NGINX
Last updated 2021-05-22
Currently, NGINX only supports one
init_by_lua_file, which is used by the Signal Sciences NGINX module. If you have your own Lua scripts embedded within NGINX, you will need to splice the Signal Sciences module into your custom Lua code.
By not using the
sigsci.conf configuration file, you will not receive configuration file updates when the module is upgraded. You should take care and review your Lua module when a Signal Sciences module release is updated.
Before you add our module into your existing Lua code, you'll need to remove any references to the
sigsci include file: Look for and remove any lines that look like:
Next, the following should be added to your NGINX configuration:
lua_shared_dict sigsci_conf 12k;lua_use_default_type off;
init_by_lua or the file specified by
init_by_lua_file, include the following snippet:
package.path = "/opt/sigsci/nginx/?.lua;" .. package.pathsigsci = require("SignalSciences")
Lastly, you will need to add an
log_by_lua into your NGINX configuration. If you already have these directives defined, copy the
sigsci.postrequest() statements to their respective Lua callers.
access_by_lua 'sigsci.prerequest()';log_by_lua 'sigsci.postrequest()';
After adding those lines to your custom Lua scripts, restart NGINX.