Skip to content

Disable specific Functions Modules of the script on paths

Conor McKnight edited this page Jun 9, 2026 · 12 revisions

So to disable specific functions of the script lets say you want to keep WAF firewall checks running and you want to disable IP address flooding checks you can do so like this.

If you are running the Latest openresy Nginx Lua builds I recommend you use rewrite_by_lua if possible if you cant use rewrite_by_lua method then use set_by_lua method.

The reason I recommend using rewrite_by_lua method over set_by_lua method if you can is a programming performance reason, Because set_by_lua works by using loadstring / load and while LuaJIT is fast it does have a slight performance trade of compared to rewrite_by_lua that does not need to use load / loadstring That means that using the example code in rewrite_by_lua is faster and more likely to withstand a DDoS attack. I provided both examples OLD and NEW because i know allot of people who use this script use OLD / Custom compiled Nginx builds that the new version may not work with.

Spoiler : rewrite_by_lua works with New Nginx Lua versions ONLY
location = /testing {

#open rewrite by lua tag
# for large configurations use
#rewrite_by_lua_file custom_settings.lua #you can make your configurations as big as you like without hitting limits
rewrite_by_lua '

if localized_global == nil then --if global not exists
localized_global = {} --define global var that script can read
end
localized_global.anti_ddos_table = {} --disable anti-ddos flood checks
localized_global.credits = 2 --disable ddos credits

'; #close rewrite by lua tag

}

location /path/testing {

#open rewrite by lua tag
# for large configurations use
#rewrite_by_lua_file custom_settings.lua #you can make your configurations as big as you like without hitting limits
rewrite_by_lua '

if localized_global == nil then --if global not exists
localized_global = {} --define global var that script can read
end
localized_global.anti_ddos_table = {} --disable anti-ddos flood checks
localized_global.credits = 2 --disable ddos credits
localized_global.content_cache = {} --disable content caching
localized_global.WAF_Header_Request_table = {} --disable WAF Header checks

'; #close rewrite by lua tag

}

### etc add your other locations and check nginx docs for regex examples like this
# Exact match - highest priority, no further matching
#location = /images {
# Prefix match that stops regex evaluation
#location ^~ /images {
# Case-sensitive regex
#location ~ \.(jpg|png|gif)$ {
# Case-insensitive regex  
#location ~* \.(jpg|png|gif)$ {
Spoiler : set_by_lua works with All Old and New Nginx Lua versions
location = /testing {

#open set by lua tag
# for large configurations use
#set_by_lua_file $localized_global custom_settings.lua #you can make your configurations as big as you like without hitting limits
set_by_lua $localized_global '

local load = load
local localized_global = [[
if localized_global == nil then --if global not exists
localized_global = {} --define global var that script can read
end
localized_global.anti_ddos_table = {} --disable anti-ddos flood checks
localized_global.credits = 2 --disable ddos credits
]]
return load(localized_global,"=localized_global_settings1")() --loadstring to run lua code from our set ngx variable

'; #close set by lua tag

}

location /path/testing {

#open set by lua tag
# for large configurations use
#set_by_lua_file $localized_global custom_settings.lua #you can make your configurations as big as you like without hitting limits
set_by_lua $localized_global '

local load = load
local localized_global = [[
if localized_global == nil then --if global not exists
localized_global = {} --define global var that script can read
end
localized_global.anti_ddos_table = {} --disable anti-ddos flood checks
localized_global.credits = 2 --disable ddos credits
localized_global.content_cache = {} --disable content caching
localized_global.WAF_Header_Request_table = {} --disable WAF Header checks
]]
return load(localized_global,"=localized_global_settings2")() --loadstring to run lua code from our set ngx variable

'; #close set by lua tag

}

### etc add your other locations and check nginx docs for regex examples like this
# Exact match - highest priority, no further matching
#location = /images {
# Prefix match that stops regex evaluation
#location ^~ /images {
# Case-sensitive regex
#location ~ \.(jpg|png|gif)$ {
# Case-insensitive regex  
#location ~* \.(jpg|png|gif)$ {

Related : Disable entire script on specific locations / paths

Clone this wiki locally