Making nginx use blocklistd

fail2ban is nice and simple to use, but has a brutal overhead on modest hardware that can handle a surprising amount of traffic. There is a more elegant solution which is much less known, called blocklistd.

tl;dr: https://code.petermolnar.net/ngx-http-blocklistd

I wrote about having fun with bots and scapers before that I brought upon myself by having nepenthes added to my server1. As things currently stand, unless you want to or can afford A LOT OF traffic, you shouldn't do what I did.

Anyhow, now that all the links are removed from everywhere it means that there's a certain path prefix that I know 100% sure it's nasty bot traffic and I'd be happy to block the IP immediately if it ends up there.

The last time I tried fail2ban, my CPU got overloaded. I then tried blocking at ASN level2, but I regularly ended up blocking M$, Google Cloud, and other things, eventually blocking some of the indieweb tooling3 from accessing my site with that blast radius.

I have turned to blocklistd4 (formerly called blacklistd) for blocking SSH and Postfix attempts, because it has it built in. It's a (Net)BSD security tool that listens on a socket for messages with IPs to be blocked by your firewall. In a sense it does the same job as fail2ban, but with much less overhead: it doesn't need logs to be writter, logs to be read and parsed, and it's written in C.

The nginx module that communicates to blocklistd didn't exist, so I decided to write it. The end results looks way simpler, than finding the resources were, but these were quite helpful:

It is now working and I'm testing how far I can take it. For what it's worth, I'm not going back to the endless AI poison maze experiment, because I can't afford to jeopardise that level of traffic on my home connection, but I will most likely put honeypot links back soon.


  1. https://petermolnar.net/article/anti-ai-nepenthes-fail2ban/index.html↩︎

  2. https://petermolnar.net/article/asn-blocking-freebsd-pf-nginx/index.html↩︎

  3. https://granary.io/↩︎

  4. https://man.freebsd.org/cgi/man.cgi?query=blocklistd&sektion=8&manpath=FreeBSD+15.1-RELEASE+and+Ports.quarterly↩︎

This entry was written by Peter Molnar, and originally posted on petermolnar dot net.