Protect Exposed Services with CrowdSec + Nginx Proxy Manager

Pair CrowdSec with Nginx Proxy Manager in Docker Compose to block vulnerability scanners automatically using real-time log parsing and shared threat lists.

Deploy CrowdSec with Nginx Proxy Manager

Mount NPM access logs into CrowdSec, configure acquisition and LAN whitelists, and attach an active bouncer.

Estimated time: PT30M

  1. Share Nginx Proxy Manager log volume

    Mount NPM's /data/logs directory read-only into the CrowdSec container in docker-compose.yml.

  2. Configure log acquisition in acquis.yaml

    Point CrowdSec to proxy-host-*_access.log and proxy-host-*_error.log with type nginx-proxy-manager.

  3. Whitelist your local LAN and Tailscale subnets

    Create a s02-enrich whitelist YAML so private IPs and local loops are never banned.

  4. Register a bouncer and inspect live decisions

    Generate an API key with cscli bouncers add and verify blocked traffic using cscli metrics.

If you publish web services like Nextcloud, Vaultwarden, or Overseerr to the internet through Nginx Proxy Manager, open your /data/logs/proxy-host-*_access.log files once and you will immediately see hundreds of automated bots probing /wp-login.php, .env, and known CVE paths every hour. TLS certificates encrypt traffic, but they do not stop bots from hitting your login forms.

CrowdSec acts like a modern, collaborative successor to Fail2ban built natively for reverse proxies and Docker. It tails your Nginx Proxy Manager logs in real time (~80–150 MB RAM, under 1% CPU), spots aggressive scanning and brute-force patterns locally, and enforces bans through a bouncer while letting you subscribe to community blocklists of known malicious IPs.

How CrowdSec Fits Alongside Nginx Proxy Manager

CrowdSec separates detection from blocking:

  1. The CrowdSec Agent (Security Engine): Reads Nginx Proxy Manager access/error logs (mounted read-only) and matches patterns against scenarios such as http-probing, http-cve, and bad user-agents.
  2. The Bouncer: Enforces decisions—either at the firewall level (crowdsec-firewall-bouncer blocking IPs in nftables/iptables before they reach Docker) or directly inside Nginx (openresty/nginx bouncer returning HTTP 403).

Pairing CrowdSec with a host firewall bouncer (for bare-metal Linux servers) or an NPM-compatible OpenResty bouncer (lepresidente/nginx-proxy-manager fork or standalone firewall bouncer) stops hostile traffic cleanly. Below we wire up the full Docker Compose CrowdSec engine watching NPM’s logs, create a LAN whitelist, and connect a firewall bouncer on the Linux host so blocked scanners get dropped at the kernel before reaching any container.

Step 1: Prepare Directories and Whitelists First

Before starting CrowdSec, create its config folder and explicitly whitelist your private LAN and VPN ranges so typos during testing never lock you out of your own apps:

Terminal window
mkdir -p /opt/docker/npm-crowdsec/crowdsec/{config,data}
mkdir -p /opt/docker/npm-crowdsec/crowdsec/config/parsers/s02-enrich

Create /opt/docker/npm-crowdsec/crowdsec/config/parsers/s02-enrich/mywhitelists.yaml:

name: local/homelab-whitelist
description: "Whitelist private LAN and Tailscale ranges"
whitelist:
reason: "Trusted homelab private networks"
ip:
- "127.0.0.1"
- "::1"
cidr:
- "192.168.1.0/24"
- "100.64.0.0/10"

Replace 192.168.1.0/24 with your home LAN subnet if different (double-check in our subnet calculator).

Step 2: Configure Log Acquisition (acquis.yaml)

Tell CrowdSec exactly which log files Nginx Proxy Manager writes inside /var/log/npm. Create /opt/docker/npm-crowdsec/crowdsec/config/acquis.yaml:

filenames:
- /var/log/npm/proxy-host-*_access.log
- /var/log/npm/proxy-host-*_error.log
- /var/log/npm/default-host_*.log
- /var/log/npm/fallback_*.log
labels:
type: nginx-proxy-manager

Line by line:

  • proxy-host-*_access.log and _error.log capture every proxied domain you configured in NPM’s UI.
  • default-host_*.log and fallback_*.log catch bots hitting your public IP directly without a valid domain name—often the noisiest scanners of all.
  • type: nginx-proxy-manager selects the official CrowdSec parser built specifically for NPM’s log format.

Step 3: Add CrowdSec to Your Nginx Proxy Manager Compose Stack

Create /opt/docker/npm-crowdsec/docker-compose.yml linking both containers cleanly (never share logs write-access—mount :ro into CrowdSec):

services:
npm:
image: jc21/nginx-proxy-manager:latest
container_name: npm
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "127.0.0.1:81:81"
volumes:
- ./npm/data:/data
- ./npm/letsencrypt:/etc/letsencrypt
crowdsec:
image: crowdsecurity/crowdsec:latest
container_name: crowdsec
restart: unless-stopped
environment:
GID: "1000"
COLLECTIONS: "crowdsecurity/nginx-proxy-manager crowdsecurity/http-cve crowdsecurity/base-http-scenarios crowdsecurity/whitelist-good-actors"
volumes:
- ./crowdsec/config:/etc/crowdsec
- ./crowdsec/data:/var/lib/crowdsec/data
- ./npm/data/logs:/var/log/npm:ro
ports:
- "127.0.0.1:8080:8080"

Key security details in that YAML:

  • 127.0.0.1:81:81 keeps NPM’s admin dashboard off the public interface (reach it via SSH tunnel or Tailscale rather than exposing port 81).
  • ./npm/data/logs:/var/log/npm:ro mounts NPM’s logs read-only so CrowdSec can inspect requests without modifying proxy data.
  • COLLECTIONS automatically installs NPM parsers, HTTP CVE rules, path-traversal/bad-bot scenarios, and search-engine crawler whitelists (like Googlebot).
  • 127.0.0.1:8080:8080 binds CrowdSec’s Local API (LAPI) strictly to localhost so host bouncers can connect without exposing port 8080 to your LAN.

Start the stack:

Terminal window
cd /opt/docker/npm-crowdsec
docker compose up -d

Wait ~20 seconds while CrowdSec pulls its initial hub collections, then confirm logs are flowing cleanly:

Terminal window
docker exec crowdsec cscli metrics

In the Acquisition Metrics table, you should see lines read incrementing for /var/log/npm/proxy-host-*_access.log.

Step 4: Enforce Bans with the Host Firewall Bouncer

Analyzing logs does nothing on its own until a bouncer enforces decisions. Installing crowdsec-firewall-bouncer-nftables (or -iptables) on the Ubuntu/Debian host drops malicious IPs at the kernel firewall—including packets headed for Docker’s DOCKER-USER chain.

First, generate an API key inside your CrowdSec container:

Terminal window
docker exec crowdsec cscli bouncers add host-firewall

Copy the printed API key immediately (it is shown only once). Now install the CrowdSec repo and bouncer package on the Linux host:

Terminal window
curl -s https://install.crowdsec.net | sudo sh
sudo apt install -y crowdsec-firewall-bouncer-nftables

Edit /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml:

mode: nftables
api_url: http://127.0.0.1:8080/
api_key: PASTE_YOUR_GENERATED_KEY_HERE
update_frequency: 10s

Restart the bouncer and check that it registered:

Terminal window
sudo systemctl enable --now crowdsec-firewall-bouncer
docker exec crowdsec cscli bouncers list

Verify the Valid column shows ✓ and Last API pull updates every 10 seconds. Check live bans anytime with:

Terminal window
docker exec crowdsec cscli decisions list

(Note: if you want a simpler setup with zero open ports on your router and no public reverse proxy exposed at all, read our Cloudflare Tunnels vs. Tailscale vs. WireGuard comparison next—and keep reading our UFW and Fail2ban guide for host-level SSH defense.)

Troubleshooting CrowdSec + Nginx Proxy Manager

1. Bouncer logs show 401 Unauthorized or connection refused

Check two things: confirm api_url uses http://127.0.0.1:8080/ matching ports: - "127.0.0.1:8080:8080", and ensure api_key matches what cscli bouncers add printed (you can regenerate anytime via cscli bouncers delete host-firewall && cscli bouncers add host-firewall).

2. CrowdSec sees Cloudflare’s IP instead of real visitors

If your DNS is proxied behind Cloudflare orange-cloud, Nginx Proxy Manager logs Cloudflare’s edge IP unless configured to trust Cloudflare headers. In NPM, add a custom snippet in /data/nginx/custom/http_top.conf containing real_ip_header CF-Connecting-IP; alongside Cloudflare’s official set_real_ip_from ranges, then restart NPM. Never run CrowdSec blindly behind a CDN without restoring real client IPs, or you risk banning Cloudflare edge nodes.

3. cscli metrics shows zero lines read

Check your path mapping. Open a shell check against the host path (ls -l /opt/docker/npm-crowdsec/npm/data/logs) to verify NPM is writing proxy-host-*_access.log files there, and confirm your NPM proxy hosts actually received HTTP traffic after CrowdSec started (CrowdSec tails new log lines from startup by default).

4. You locked out your own testing IP

View current active bans (docker exec crowdsec cscli decisions list) and clear a single IP instantly:

Terminal window
docker exec crowdsec cscli decisions delete --ip 203.0.113.50

Frequently Asked Questions

How is CrowdSec different from Fail2ban?

Fail2ban only reacts after an attacker hits your own logs multiple times. CrowdSec parses your Nginx Proxy Manager logs locally AND shares anonymized attack signals with a community network, allowing you to block known aggressive botnets proactively before they ever test a password on your server.

How much RAM and CPU does CrowdSec use in a homelab?

The CrowdSec engine container typically uses 80–150 MB of RAM and well under 1% CPU on an Intel N100 or Raspberry Pi 4, while the lightweight OpenResty/Nginx bouncer plugin adds negligible overhead per request.

Can CrowdSec protect my server if I use Cloudflare in front of Nginx Proxy Manager?

Yes, provided Nginx Proxy Manager restores the real visitor IP from Cloudflare's CF-Connecting-IP header. Otherwise CrowdSec sees Cloudflare's edge IP on every error and could ban Cloudflare instead of the abusive client.

What happens if CrowdSec falsely bans me while testing my own apps?

Add your home LAN subnet (such as 192.168.1.0/24) to a custom CrowdSec whitelist YAML file, and unban any test IP anytime with docker exec crowdsec cscli decisions delete --ip YOUR_IP.

Portrait of Guillermo

Written by Guillermo

IT Student & Home Server Enthusiast

Building private clouds to break free from Big Tech. I document everything I learn about home servers and self-hosting on MyHomeServerGuide.

More about the author