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.
On this page
- How CrowdSec Fits Alongside Nginx Proxy Manager
- Step 1: Prepare Directories and Whitelists First
- Step 2: Configure Log Acquisition (acquis.yaml)
- Step 3: Add CrowdSec to Your Nginx Proxy Manager Compose Stack
- Step 4: Enforce Bans with the Host Firewall Bouncer
- Troubleshooting CrowdSec + Nginx Proxy Manager
- 1. Bouncer logs show 401 Unauthorized or connection refused
- 2. CrowdSec sees Cloudflare’s IP instead of real visitors
- 3. cscli metrics shows zero lines read
- 4. You locked out your own testing IP
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
Share Nginx Proxy Manager log volume
Mount NPM's /data/logs directory read-only into the CrowdSec container in docker-compose.yml.
Configure log acquisition in acquis.yaml
Point CrowdSec to proxy-host-*_access.log and proxy-host-*_error.log with type nginx-proxy-manager.
Whitelist your local LAN and Tailscale subnets
Create a s02-enrich whitelist YAML so private IPs and local loops are never banned.
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:
- 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. - The Bouncer: Enforces decisions—either at the firewall level (
crowdsec-firewall-bouncerblocking IPs innftables/iptablesbefore they reach Docker) or directly inside Nginx (openresty/nginxbouncer returning HTTP403).
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:
mkdir -p /opt/docker/npm-crowdsec/crowdsec/{config,data}mkdir -p /opt/docker/npm-crowdsec/crowdsec/config/parsers/s02-enrichCreate /opt/docker/npm-crowdsec/crowdsec/config/parsers/s02-enrich/mywhitelists.yaml:
name: local/homelab-whitelistdescription: "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_*.loglabels: type: nginx-proxy-managerLine by line:
proxy-host-*_access.logand_error.logcapture every proxied domain you configured in NPM’s UI.default-host_*.logandfallback_*.logcatch bots hitting your public IP directly without a valid domain name—often the noisiest scanners of all.type: nginx-proxy-managerselects 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:81keeps NPM’s admin dashboard off the public interface (reach it via SSH tunnel or Tailscale rather than exposing port81)../npm/data/logs:/var/log/npm:romounts NPM’s logs read-only so CrowdSec can inspect requests without modifying proxy data.COLLECTIONSautomatically installs NPM parsers, HTTP CVE rules, path-traversal/bad-bot scenarios, and search-engine crawler whitelists (like Googlebot).127.0.0.1:8080:8080binds CrowdSec’s Local API (LAPI) strictly tolocalhostso host bouncers can connect without exposing port8080to your LAN.
Start the stack:
cd /opt/docker/npm-crowdsecdocker compose up -dWait ~20 seconds while CrowdSec pulls its initial hub collections, then confirm logs are flowing cleanly:
docker exec crowdsec cscli metricsIn 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:
docker exec crowdsec cscli bouncers add host-firewallCopy the printed API key immediately (it is shown only once). Now install the CrowdSec repo and bouncer package on the Linux host:
curl -s https://install.crowdsec.net | sudo shsudo apt install -y crowdsec-firewall-bouncer-nftablesEdit /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml:
mode: nftablesapi_url: http://127.0.0.1:8080/api_key: PASTE_YOUR_GENERATED_KEY_HEREupdate_frequency: 10sRestart the bouncer and check that it registered:
sudo systemctl enable --now crowdsec-firewall-bouncerdocker exec crowdsec cscli bouncers listVerify the Valid column shows ✓ and Last API pull updates every 10 seconds. Check live bans anytime with:
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:
docker exec crowdsec cscli decisions delete --ip 203.0.113.50Frequently 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.