Menu

A 4-million-entry IP blocklist in nginx without 200 MB per worker: sorted ranges, mmap and a binary search in LuaJIT
📰

A 4-million-entry IP blocklist in nginx without 200 MB per worker: sorted ranges, mmap and a binary search in LuaJIT

DEV Community: opensource·Jikwang Moon·10 days ago
#Kq0wSb7Y
#devtoopensource#devto#dev#file#local
Long article (1891 words) — no AI summary yet.
Reading 0:00
15s threshold

A user of Corvus , my open-source gateway on top of

OpenResty, opened a short issue: "This community blocklist is 50 MB and fails to download (limit

is 5 MB). Please support larger blocklists."

Raising the limit would have taken one line. It would also have been a bad idea, and fixing it

properly turned into one of the more satisfying pieces of work on the project. This post is about

that fix, because the technique works for any nginx/OpenResty setup that needs to check client

addresses against a big list.

Why raising the limit wasn't enough

The list in question has about 3.9 million IPv4 addresses and networks, one per line. At the

time, Corvus handled IP lists the obvious way: the control plane stored the entries, wrote them into

the gateway's rule file, and every nginx worker loaded them into a Lua table when the configuration

loaded.

That's fine for a few thousand entries.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.