📍 Article principal du cluster : CrowdSec 2026 : guide complet.
Bloquer une IP au niveau iptables est efficace mais brutal. Au niveau HTTP via Caddy ou Nginx, on peut afficher un captcha, throttle, ou rediriger. Ce tutoriel détaille la configuration des bouncers HTTP pour les deux reverse proxies les plus utilisés.
Prérequis
- CrowdSec installé sur le VPS (voir tutoriel installation).
- Caddy 2 ou Nginx 1.18+ en façade.
- Niveau attendu : intermédiaire.
- Temps estimé : 30-45 minutes.
Bouncer Caddy
Étape 1 — Installer le bouncer Caddy
apt install -y crowdsec-caddy-bouncer
Pour Caddy compilé custom : xcaddy build --with github.com/hslatman/caddy-crowdsec-bouncer.
Étape 2 — Générer une API key bouncer
cscli bouncers add caddy-bouncer
# Note la clé retournée, par exemple ABC123XYZ
Étape 3 — Configuration Caddyfile
{
order crowdsec first
crowdsec {
api_url http://127.0.0.1:8080
api_key ABC123XYZ
ticker_interval 15s
appsec_url http://127.0.0.1:7422 # optionnel pour AppSec
}
}
vault.votre-entreprise.com {
crowdsec
reverse_proxy vaultwarden:80
}
wiki.votre-entreprise.com {
crowdsec
reverse_proxy outline:3000
}
Étape 4 — Recharger Caddy
caddy validate --config /etc/caddy/Caddyfile
systemctl reload caddy
Étape 5 — Test bouncer Caddy
# Bannir une IP de test
cscli decisions add --ip 1.2.3.4 --duration 1h --type ban
# Tester (depuis 1.2.3.4 ou simulant)
curl -H "X-Forwarded-For: 1.2.3.4" https://vault.votre-entreprise.com
# Doit retourner 403 Forbidden
Bouncer Nginx
Étape 1 — Installer le bouncer Nginx
apt install -y crowdsec-nginx-bouncer
Le bouncer s’installe via module Lua nginx-mod-luajit (auto via apt).
Étape 2 — Générer une API key
cscli bouncers add nginx-bouncer
# Note la clé
Étape 3 — Configuration /etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf
API_URL=http://127.0.0.1:8080
API_KEY=YOUR_KEY
SECURE=false
LOG_FILE=/var/log/crowdsec-nginx-bouncer.log
UPDATE_FREQUENCY=10
DEFAULT_REMEDIATION=ban
TEMPLATE_DIR=/var/lib/crowdsec/lua/templates/
Étape 4 — Vérifier nginx.conf
Le bouncer ajoute automatiquement access_by_lua_file dans le main http block. Vérifier :
nginx -t
systemctl reload nginx
Captcha au lieu de ban
Pour ne pas bannir totalement (cas de sites e-commerce où des clients légitimes peuvent être faux positifs), utiliser captcha :
# Configuration profile
nano /etc/crowdsec/profiles.yaml
name: captcha_remediation
filters:
- Alert.Remediation == true && Alert.GetScenario() contains "http"
decisions:
- type: captcha
duration: 4h
notifications:
- http_default
on_success: continue
Recharger : systemctl reload crowdsec.
AppSec : protection L7 avancée
CrowdSec AppSec (CrowdSec 1.6+) fournit un WAF style ModSecurity. Détecte SQLi, XSS, path traversal au niveau requête.
cscli collections install crowdsecurity/appsec-virtual-patching
cscli collections install crowdsecurity/appsec-generic-rules
# Ajouter dans Caddyfile
crowdsec {
appsec_url http://127.0.0.1:7422
}
Erreurs fréquentes
| Erreur | Cause | Solution |
|---|---|---|
| Bouncer Caddy 401 | API key incorrecte | Régénérer + update Caddyfile |
| Captcha boucle | Cookie session pas conservé | Verify Caddy session config |
| Lua error nginx | Module Lua manquant | apt install nginx-mod-luajit |
| Real IP via CDN faux | X-Forwarded-For ignoré | Trust proxy via real_ip_header |
| AppSec faux positifs | Règles trop strictes | Tuner whitelist AppSec |
| Performance dégradée | Trop de requêtes vers LAPI | Augmenter ticker_interval |
Adaptation au contexte ouest-africain
Trois précisions. Real IP via Cloudflare : si Cloudflare en façade, configurer trusted_proxies cloudflare dans Caddy pour récupérer vraie IP visiteur. Sinon, vous bloquez Cloudflare. Captcha mobile-friendly : Google reCAPTCHA challenge sur 4G partagée à Niamey peut être lent. Utiliser hCaptcha (plus léger). Géo-blocking soft : ne pas hard-block tout pays, mais throttle selon score risque.
Tutoriels frères
FAQ
Caddy ou Nginx + bouncer ? Caddy plus simple, Nginx plus mature. Performance équivalente.
Performance avec bouncer ? +1-3 ms latence par requête. Négligeable.
AppSec gratuit ? Oui en self-hosted. Premium WAF rules payantes.
Bouncer multi-Caddy ? Une API key par instance, ou clé partagée si LAPI central.
Désactiver temporairement ? cscli decisions delete --all efface bans actifs.
Pour aller plus loin
- 🔝 Retour au pilier : Guide complet CrowdSec 2026
- Documentation Bouncers : docs.crowdsec.net/u/bouncers