Running your own apps on a VPS puts you on the open internet, where bots and bad IPs try to break in all day. A regular firewall just opens or closes ports; it can't tell if traffic on port 443 is a real visitor or an attack. That's where protect self-hosted apps with CrowdSec comes in. It sits between your reverse proxy and the outside world, reads behavior patterns, and automatically bans offenders in real time.
This guide teaches you to deploy CrowdSec with Docker Compose, connect it to both Traefik and Caddy using the right bouncer for each.
What Is CrowdSec and Why Do You Need It?
CrowdSec is a free, open-source security tool that watches your logs and blocks attacks. Unlike a regular firewall, which only follows fixed rules, CrowdSec learns attack patterns and shares them with a global community. So if one server spots a bad IP, every other CrowdSec user gets protected from it.
It works in two parts:
Security Engine (Agent): Reads logs, detects threats, and makes decisions.
Remediation Component (Bouncer): Enforces those decisions at the entry point, in this case, inside Traefik or Caddy.
If you run a Linux VPS Server with apps exposed to the internet, pairing Traefik or Caddy with CrowdSec is one of the best security setups you can use.
Prerequisites to Protect Self-Hosted Apps with CrowdSec
Before starting to protect self-hosted apps with CrowdSec, make sure you have:
A Linux VPS running Ubuntu 24.04.
Docker and Docker Compose are installed.
Either Traefik or Caddy is already planned as your reverse proxy.
At this point, protect self-hosted apps with CrowdSec is not complete yet because CrowdSec still needs logs from Traefik or Caddy.
Part 2. Protect Self-Hosted Apps with CrowdSec Using Traefik
This section covers integrating CrowdSec with Traefik using the official Traefik plugin. Use this if Traefik is your reverse proxy.
Important Note: Use the maxlerebourg/crowdsec-bouncer-traefik-plugin, not the older fbonalair/traefik-crowdsec-bouncer. The older one does not support the AppSec component and is no longer actively maintained.
Create Traefik YAML File
This file tells CrowdSec to read Traefik access logs. Create the file with the command below:
You can define the CrowdSec middleware as Docker labels on Traefik itself, or as a dynamic config file. The label method is the most common for Docker-based setups.
If you put Cloudflare or another proxy in front of Traefik, add forwardedHeadersTrustedIPs to the middleware config, so CrowdSec sees the real visitor IP instead of the proxy's IP:
For every service you want to protect, add the middleware to its router labels. For example, if your app is in ~/myapp/docker-compose.yml, open that file:
Then, update the CrowdSec Compose file with this Caddy config:
Note: ghcr.io/buildplan/cs-caddy is a community-maintained image, not an official Caddy or CrowdSec build. If you prefer an official path, build your own image with xcaddy and the github.com/hslatman/caddy-crowdsec-bouncer module instead.
Now protect self-hosted apps with CrowdSec is active for that Caddy site block.
Part 4. Add AppSec Firewall Layer
AppSec is CrowdSec's web application firewall layer. It can help block exploit payloads and bad requests. To create the file, you can use the command below:
1name: crowdsecurity/whitelists2description:"Whitelist local and private IPs"3whitelist:4reason:"private ranges"5ip:6-"127.0.0.1"7-"::1"8cidr:9-"10.0.0.0/8"10-"172.16.0.0/12"11-"192.168.0.0/16"
Restart CrowdSec:
Bash
cd~/crowdsecdockercomposerestartcrowdsec
This is one of the best small changes you can make when you protect self-hosted apps with CrowdSec on one VPS.
Part 6. Verify Everything Works Correctly with CrowdSec
It is recommended to check everything after your setup.
First, check that logs are being read:
Bash
dockerexeccrowdseccsclimetrics
Look for acquisition metrics. You should see lines for Traefik or Caddy logs.
Then, check if the bouncer is connected:
Bash
dockerexeccrowdseccsclibouncerslist
You should see traefik-bouncer or caddy-bouncer with a recent last pull time.
Now you can manually ban your IP. Find your public IP:
Traefik and Caddy are great at routing traffic and handling HTTPS, but they do not act like a smart security layer by themselves. CrowdSec adds that missing layer by reading logs, detecting attacks, and blocking bad traffic before it reaches your apps.
If you want a simple and practical way to protect self-hosted apps with CrowdSec, this setup is one of the best options for a single VPS. It is lightweight, works well with Docker, and is easy to test once the files are in the right place.
Harden your exposed apps on a PerLod Linux VPS before brute-force and bot traffic become real incidents.
We hope you enjoy this guide. For more information, you can check the CrowdSec official docs.
Yes. UFW filters ports. CrowdSec reads app and proxy logs.
No. Pick one reverse proxy and connect CrowdSec to that one.
We use cookies to run PerLod and to understand how the site is used. You can accept everything, or open Manage to turn individual categories off. Cookie policy.