Skip to content

Script Overrides

Conor McKnight edited this page Nov 7, 2025 · 3 revisions

The ability for script settings to be controlled from nginx configuration file nginx.conf or vhosts useful for those who do not want to edit the script but can instead use their vhosts virtual hosts or nginx config files to change settings of the script.

Example: nginx.conf inside the http block

http {

#shared memory addresses in http block
lua_shared_dict antiddos 70m; #Anti-DDoS shared memory zone to track requests per each unique user
lua_shared_dict antiddos_blocked 70m; #Anti-DDoS shared memory where blocked users are put
lua_shared_dict ddos_counter 10m; #Anti-DDoS shared memory zone to track total number of blocked users
lua_shared_dict jspuzzle_tracker 70m; #Anti-DDoS shared memory zone monitors each unique ip and number of times they stack up failing to solve the puzzle

#nginx config settings etc
access_by_lua_file anti_ddos_challenge.lua;
#more config settings and some server stuff

# Override Anti-DDoS script settings with our own
init_by_lua '
localized_global = {} --define global var that script can read
localized_global.secret = " enigma" --nginx config now sets secret key and the script will use the secret key from here
localized_global.credits = 2 --disable ddos credits
';
}

I want each website or server address to use its own settings ? Heres how.

http {

#shared memory addresses in http block
lua_shared_dict antiddos 70m; #Anti-DDoS shared memory zone to track requests per each unique user
lua_shared_dict antiddos_blocked 70m; #Anti-DDoS shared memory where blocked users are put
lua_shared_dict ddos_counter 10m; #Anti-DDoS shared memory zone to track total number of blocked users
lua_shared_dict jspuzzle_tracker 70m; #Anti-DDoS shared memory zone monitors each unique ip and number of times they stack up failing to solve the puzzle

#nginx config settings etc
access_by_lua_file anti_ddos_challenge.lua;
#more config settings and some server stuff

server {
listen 80; #ipv4
listen [::]:80; #ipv6
server_name  localhost;

# Override Anti-DDoS script settings with our own
set_by_lua '
localized_global = {} --define global var that script can read
localized_global.secret = " enigma" --nginx config now sets secret key and the script will use the secret key from here
localized_global.credits = 2 --disable ddos credits
';

location / {
root   html;
index  index.html index.htm;
}

} #end server block

} #end http block

As you can see rather than using init_by_lua what would be in the http { block we use set_by_lua what can be used inside the server { block and as you can see from this page the execution order of phases in nginx lua set_by_ executes before the access phase.

Wiki page on Execution ordering

Clone this wiki locally