Working with multiple Lua scripts in NGINX

Currently, NGINX only supports one init_by_lua or init_by_lua_file, which is used by the Next-Gen WAF NGINX module. If you have your own Lua scripts embedded within NGINX, you will need to splice the Next-Gen WAF module into your custom Lua code.

NOTE

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 Next-Gen WAF module release is updated.

Removing the Next-Gen WAF NGINX Lua module

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:

include /opt/sigsci/nginx/sigsci.conf;

Next, the following should be added to your NGINX configuration:

lua_shared_dict sigsci_conf 12k;
lua_use_default_type off;

Within your init_by_lua or the file specified by init_by_lua_file, include the following snippet:

package.path = "/opt/sigsci/nginx/?.lua;" .. package.path
sigsci = require("SignalSciences")

Lastly, you will need to add an access_by_lua and log_by_lua into your NGINX configuration. If you already have these directives defined, copy the sigsci.prerequest() and 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.

Was this guide helpful?

Do not use this form to send sensitive information. If you need assistance, contact support. This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.