Back to Article List

CrowdSec WAF and bot detection on Apache with mod_crowdsec

CrowdSec WAF and bot detection on Apache with mod_crowdsec

mod_crowdsec 1.0 is a rewrite of CrowdSec's Apache bouncer, and it's the first version that forwards requests to the AppSec component. That means Apache can now block virtual-patch hits and serve the same bot challenge the nginx bouncer has had for a while. This guide adds the module to an Ubuntu 24.04 server that already runs CrowdSec, moves it to stream mode and turns on the WAF and bot detection. It also covers how the module behaves with the Apache features most sites rely on: .htaccess, Basic auth, redirects, ModSecurity and a reverse proxy in front.

A version note before anything else. The documentation describes version 1.0. As I write this, in November 2026, the newest release on GitHub is 1.0.0-rc2 and the final 1.0.0 isn't tagged yet, so everything below was tested on rc2. When the final release is out, change the version in the download step and read its release notes for anything that moved.

What the server needs before you install mod_crowdsec

The module needs Apache 2.4.16 or newer, mod_socache_shmcb (the package loads it for you), libcurl and a CrowdSec Local API it can reach. On Ubuntu 24.04 that's the stock apache2 package (2.4.58 on my server) plus CrowdSec from its own apt repository. I started from the Apache + CrowdSec one-click template on a CrowdSec VPS, and any Ubuntu 24.04 server with Apache and CrowdSec installed works the same way. If CrowdSec isn't on the server yet, the complete guide to CrowdSec in production starts with the install.

My server also ran the nftables firewall bouncer (sudo cscli bouncers list shows what yours runs), and two things follow from that. The firewall bouncer drops banned IPs before Apache sees them, so testing a ban from your own machine needs a workaround, shown below. And CrowdSec will ban you if your tests produce enough 403s. Halfway through my AppSec tests the http-generic-403-bf scenario banned my test machine, and with the firewall bouncer running a ban cuts SSH as well as HTTP. Allowlist your own address before you start, or keep a console session open. The guide to rolling out CrowdSec without lockouts covers the order I'd switch things on in.

Upgrade CrowdSec to the current version

The package lists on a server image can be months old, so refresh them and upgrade the engine first. Bot detection depends on engine features that are still changing release to release, and the hub collections expect a recent engine.

sudo apt update
sudo apt install --only-upgrade crowdsec
cscli version

The version should read 1.8.2 or newer. The upgrade's post-install step also refreshed the hub index, upgraded the installed parsers and scenarios, rewrote the files in /etc/crowdsec/acquis.d/ and then asked for a reload. The service stayed up throughout. Reload it so the new hub items load:

sudo systemctl reload crowdsec

Download and install the mod_crowdsec .deb

mod_crowdsec 1.0 isn't in an apt repository. The packages are attached to the cs-apache2-bouncer releases on GitHub, one per distribution and architecture. For Ubuntu 24.04 on x86 the download is:

wget https://github.com/crowdsecurity/cs-apache2-bouncer/releases/download/v1.0.0-rc2/crowdsec-apache2-bouncer_1.0.0.rc2_noble_amd64.deb
sha256sum crowdsec-apache2-bouncer_1.0.0.rc2_noble_amd64.deb

Watch the file name. The package inside reports its version the Debian way, 1.0.0~rc2, and a URL built from that (with the tilde) returns a 404. In the download URL the version is written 1.0.0.rc2. On an ARM server, use arm64 in place of amd64.

The release files aren't GPG-signed, so the checksum is the only integrity check you get. The rc2 package I installed was 87,568 bytes with this SHA-256:

e8b5f0dd78c6408cece9396ea9e762afddd2abbcb5a73fe6856b23431f40a975

Install it with apt so the dependencies come along (dpkg -i only works if they're already there):

sudo apt install ./crowdsec-apache2-bouncer_1.0.0.rc2_noble_amd64.deb

Because cscli is on the same server, the post-install script registers the bouncer for you. It prints "API Key successfully created", writes the key into /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf, enables the module and restarts Apache. That restart caught me out: I expected a reload, and the install did a full graceful restart with a new main process. On a busy site, run it in a quiet hour.

apt install output for the mod_crowdsec rc2 package ending with API Key successfully created and Enable module crowdsec

The post-install script finds cscli, creates the API key and enables the module.

sudo cscli bouncers list
apache2ctl -M | grep -E 'crowdsec|socache'

The list should show a bouncer named cs-apache2-bouncer- followed by a Unix timestamp (if it ever ends up with a missing or wrong key, fixing the CrowdSec API access forbidden error covers re-registering it). Apache should list crowdsec_module (shared).

What the shipped mod_crowdsec configuration does

Everything lives in /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf. The values the package writes differ from the directive defaults in the reference table, so check which of the two a line comes from before you copy it:

DirectiveIn the shipped fileDefault if the line is missing
CrowdsecOn, at server levelOff
CrowdsecModelivelive (the docs recommend stream)
CrowdsecFallbackallowfail
CrowdsecBlockedHTTPCode403429
CrowdsecCacheshmcb:crowdsec(16777216)none
CrowdsecAppsecURL, CrowdsecAppseccommented outnone, Off

The response code differs in the same way: a build from source with a minimal config answers blocked requests with 429, where this guide and the official quickstart expect 403.

CrowdsecFallback allow lets requests through when the Local API can't be reached. I'd keep it on a public site, because restarting CrowdSec shouldn't take the website down with it.

Switch mod_crowdsec to stream mode

In live mode the module asks the Local API about each new client and caches the answer for 60 seconds. Stream mode pulls the whole decision list every 10 seconds into shared memory, so no request ever waits on the API. The docs recommend stream, and the shipped file still says live:

sudo sed -i 's/^CrowdsecMode live/CrowdsecMode stream/' /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf

The 16 MB cache in the shipped line holds about 100,000 decisions at roughly 128 bytes each. That's plenty for one site on the community blocklist. If you subscribe to large blocklists, raise the size inside CrowdsecCache, because a cache that's too small evicts decisions and only the error log and the status page tell you.

Add the status page while you're in there. It's the quickest way to see what the module holds. Create /etc/apache2/conf-available/crowdsec-status.conf:

<Location /crowdsec-status>
    SetHandler crowdsec-status
    Crowdsec Off
    CrowdsecAppsec Off
    Require ip 127.0.0.1
</Location>
sudo a2enconf crowdsec-status
sudo apachectl configtest && sudo systemctl reload apache2
curl -s http://127.0.0.1/crowdsec-status

Keep the CrowdsecAppsec Off line even before AppSec is on. Once bot detection runs, a status page without it answers with the challenge page instead of the numbers. The docs warn about this, and I checked it: it does.

The output starts with mode: stream and primed: yes, then counters for pulls, stored, processed, dropped and active_decisions by origin. I timed how long a new decision took to reach Apache: between 6.3 and 10.4 seconds over four tries, and about the same for a deleted decision to stop blocking. The documented worst case with the default timings is 12 seconds in stream mode and 62 in live mode.

crowdsec-status page showing mode: stream, active decisions by origin and primed: yes

The status page after the switch: stream mode, primed, three decisions held in the cache.

The module also reports usage metrics to the Local API, so sudo cscli metrics show bouncers lists it next to the firewall bouncer. I set CrowdsecMetricsInterval 1m at server level while testing, and the first numbers showed up within a couple of minutes.

cscli metrics show bouncers listing the Apache bouncer with 91 dropped and 216 processed requests

The Apache bouncer reports dropped and processed requests by origin, next to the firewall bouncer.

Test a CrowdSec ban on Apache without locking yourself out

The obvious test, banning your own IP and loading the site, shows nothing about Apache while the firewall bouncer runs. The firewall drops the packets first, so the browser times out and SSH goes with it. That's right for a real attacker and useless for a test. I banned my test machine for one minute to confirm it: HTTP timed out after 10 seconds and SSH froze; both came back when the decision expired.

The test that shows the module at work gives Apache a fake client address from the documentation range, through X-Forwarded-For on the loopback interface:

sudo cscli decisions add --ip 192.0.2.1 --duration 10m
printf 'RemoteIPHeader X-Forwarded-For\nRemoteIPTrustedProxy 127.0.0.1\n' | sudo tee /etc/apache2/conf-available/test-remoteip.conf
sudo a2enmod remoteip
sudo a2enconf test-remoteip
sudo systemctl reload apache2
sleep 12
curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Forwarded-For: 192.0.2.1' http://127.0.0.1/

The last line prints 403, and any other address prints 200. The sleep covers the stream-mode pull. Remove the trust when you're done, because it lets anything on the server pick its own client address:

sudo a2disconf test-remoteip
sudo a2dismod remoteip
sudo systemctl reload apache2

If you lock yourself out anyway, removing a CrowdSec decision takes one cscli command from a console session.

Turn on the CrowdSec AppSec WAF for Apache

The engine side matches nginx: two collections and an acquisition file that opens the AppSec listener on port 7422.

sudo cscli collections install crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules
sudo tee /etc/crowdsec/acquis.d/appsec.yaml > /dev/null <<'EOF'
appsec_configs:
  - crowdsecurity/appsec-default
labels:
  type: appsec
listen_addr: 127.0.0.1:7422
source: appsec
EOF
sudo systemctl restart crowdsec
ss -ltn | grep 7422

The quickstart says to allow about half a minute for the listener. Mine was up 4.3 seconds after the restart with these two collections, and 15 seconds once the bot-detection configs were added later. Then uncomment the two AppSec lines in the bouncer config (lines 53 and 88 in rc2) and reload Apache:

sudo sed -i -E 's|^#(CrowdsecAppsecURL http://127.0.0.1:7422)|\1|; s|^#(CrowdsecAppsec On)$|\1|' /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf
sudo apachectl configtest && sudo systemctl reload apache2

From another machine, ask for a file no site should serve:

curl -I http://YOUR_SERVER_IP/.env

The answer is 403 Forbidden. sudo cscli metrics show appsec counts one blocked request, and the rule that fired is vpatch-env-access. Before you trust a 403, make sure AppSec sent it. The quickstart names two other causes: your own IP already being banned, and a <FilesMatch "^\."> deny somewhere in the Apache config. The access log tells them apart, which is the next section.

cscli metrics show appsec with 3 requests processed, 1 blocked and the vpatch-env-access rule triggered once

One request blocked, and the rule behind it is vpatch-env-access.

The OWASP Core Rule Set works on Apache the way the CrowdSec AppSec WAF guide for nginx describes it: install crowdsecurity/appsec-crs and add crowdsecurity/crs to appsec_configs. It runs out-of-band, so a classic ?id=1' OR '1'='1 probe still gets a 200 while the engine raises an alert with its anomaly score. For the first weeks on a live site, watching without blocking is what you want.

Log CrowdSec decisions in the Apache access log

The module sets three variables on every request: CROWDSEC_STATUS, CROWDSEC_SOURCE and CROWDSEC_APPSEC_STATUS. A custom log format puts them next to the status code. This line can go in a file under conf-available:

LogFormat "%h %l %u %t \"%r\" %>s %b cs=%{CROWDSEC_STATUS}e src=%{CROWDSEC_SOURCE}e appsec=%{CROWDSEC_APPSEC_STATUS}e" crowdsec

The CustomLog line that uses it has to go inside the virtual host. I put mine at server level first and the file stayed empty, because Ubuntu's 000-default.conf defines its own CustomLog and a vhost that has one doesn't use the server's. In /etc/apache2/sites-available/000-default.conf, inside <VirtualHost *:80>:

CustomLog ${APACHE_LOG_DIR}/access.log combined
CustomLog ${APACHE_LOG_DIR}/crowdsec.log crowdsec

After a reload the lines look like this, a banned test address first and a normal request second:

192.0.2.6 - - [18/Nov/2026:00:38:20 +0000] "GET / HTTP/1.1" 403 274 cs=ban src=cache appsec=-
127.0.0.1 - - [18/Nov/2026:00:38:20 +0000] "GET / HTTP/1.1" 200 10671 cs=allow src=cache appsec=-

Apache log line for HEAD /.env with status 403 and cs=ban src=cache appsec=ban

A WAF block in the same log: 403 with appsec=ban. The line below it is a request AppSec allowed.

appsec=ban means the WAF blocked the request. cs=ban with appsec=- means a decision blocked it before AppSec was asked, with one exception that catches people out.

Fix 403 errors on large uploads with CrowdsecAppsecBodyLimit

Upload form failing for everyone since AppSec went on? AppSec inspects request bodies up to CrowdsecAppsecBodyLimit, 1 MB by default, and the default action for anything larger is to block it. A 2 MB POST got a 403 on every path of my server. In the log that 403 reads cs=ban src=cache appsec=-, exactly like an IP ban, so it's easy to go looking for a decision that doesn't exist.

Raise the limit only where uploads happen:

<Location /upload>
    CrowdsecAppsecBodyLimit 5m
</Location>

With that in place the same 2 MB POST reached Apache on /upload and still got a 403 everywhere else. Each worker can buffer up to the limit, so the worst case for memory is the limit times MaxRequestWorkers. Leave CrowdsecAppsecBodyLimitAction on its default: switching it to bypass lets anyone skip the WAF by padding a request past the limit.

Add CrowdSec bot detection to Apache

Nothing changes on the Apache side. With CrowdsecAppsec On set, bot detection is an engine setting: install the collection and add its configs to the AppSec acquisition file.

sudo cscli collections install crowdsecurity/appsec-bot-challenge
sudo tee /etc/crowdsec/acquis.d/appsec.yaml > /dev/null <<'EOF'
appsec_configs:
  - crowdsecurity/appsec-default
  - crowdsecurity/crs
  - crowdsecurity/appsec-bot-*
labels:
  type: appsec
listen_addr: 127.0.0.1:7422
source: appsec
EOF
sudo systemctl restart crowdsec
sudo grep "WAF challenge runtime initialized" /var/log/crowdsec.log

Leave out the crs line if you skipped the Core Rule Set. Without the "runtime initialized" line the engine has no challenge to serve, and requests pass as before. Mine printed it with cookie_ttl=12h0m0s and cookie_same_site=Lax.

crowdsec.log line WAF challenge runtime initialized with cookie_same_site=Lax and cookie_ttl=12h0m0s

This log line means the engine has a challenge to serve.

Collection 0.8 is split into sub-collections for scoring, detections, good bots and excluded paths. The wildcard loads both the default scoring config and the new balanced one, along with experimental detections that only raise alerts for now.

A plain curl to the site now gets a 200 with the page title "CrowdSec Challenge" in place of your content. /robots.txt, static files and API-style paths are exempt, so well-behaved crawlers and your uptime monitor still get through.

curl response from Apache: 200 OK, one Content-Security-Policy header and the page title CrowdSec Challenge

To curl, the challenge is a 200 with the engine's own Content-Security-Policy and the title CrowdSec Challenge.

A headless Chromium driven by Playwright loaded the challenge, ran its scripts, submitted and stayed stuck on the challenge page. The engine scored it 570, with cdp, webdriver and bot_user_agent among the reasons.

cscli alerts inspect for a rejected headless browser: request_score 570 and score_reasons starting with cdp=100

The alert for the headless browser: score 570, with cdp and webdriver at the top of the reasons.

A real Chrome passes without the visitor doing anything. The page runs its checks for a moment, posts the result to /crowdsec-internal/challenge/submit, gets a 200 back with the cookie and reloads the page, which Apache now serves (cs=allow appsec=allow in the log). On Apache there's no redirect in between, so don't go looking for a 307.

Test the challenge with developer tools closed. With DevTools open, my own Chrome got "Verification rejected", in a normal window and in Incognito alike. The engine scored every one of those attempts 100 with a single reason, cdp: an open DevTools attaches the Chrome DevTools Protocol, the same automation channel a headless bot uses. Closing DevTools and reloading passed at once. A rejection raises a crowdsecurity/rejected-browser-submission alert and no ban, so the visitor just sees the challenge again. If you want to inspect the cookie, pass first and open DevTools afterwards.

CrowdSec challenge page in Chrome showing Verification rejected while the DevTools Network panel is open

With DevTools open, a real Chrome is rejected: the open panel is what the check detects.

Scoring, thresholds, the strict and permissive overlays and master_secret are engine features and behave as they do on nginx; the CrowdSec bot detection guide for nginx explains them. Apache has no captcha, though, and challenge or captcha decisions that arrive through the stream are enforced as bans.

Content-Security-Policy and the CrowdSec challenge page on Apache

On nginx, a site-wide Content-Security-Policy and the engine's own policy both land on the challenge page. The browser enforces both and the challenge freezes on a blank page. The docs fix it on nginx with a map. On Apache you don't need a fix.

I set a CSP four ways: Header always set in the vhost, Header set in the vhost, both forms in .htaccess with AllowOverride All, and a PHP page sending its own header through PHP-FPM. Every challenge response carried exactly one CSP, the engine's, and the challenge completed each time. Normal pages kept the site's policy. The module answers in the access phase, before mod_headers or PHP get a turn, and its source removes any CSP already set before writing its own. The comment in crowdsec_appsec.c says why:

a Content-Security-Policy the engine sends and one the operator set would both go on the wire and the browser would enforce their intersection - a blank challenge page

Challenge only wp-login.php with a Location block

A full-site challenge is heavy for a blog where only /wp-login.php draws the bots. Turn both switches off at server level in the bouncer config (Crowdsec Off and CrowdsecAppsec Off), then back on for the one path in the vhost:

<Location /wp-login.php>
    Crowdsec On
    CrowdsecAppsec On
</Location>

Now / serves the normal page, /wp-login.php serves the challenge, and /.env goes back to a plain 404 because AppSec is off there as well. Decisions follow the same scope: a banned IP could still load the home page and got its 403 only on the login page. You give up the site-wide ban, so I'd only do this where the firewall bouncer handles bans for everything else.

For site-wide settings, the docs prefer server level over <Location />, because the merge order of Location blocks can override an opt-out such as the status page. If you find the <Location /> form in an older example, use the server-level form in its place.

Your idea deserves better hosting

24/7 support 30-day money-back guaranteeRefund covers the VPS plan on your first order. Cancel anytime
Betalingscyclus

VPS.S1

£4.57 Save  17 %
£3.81 Maandelijks
  • 2 vCPU AMD EPYC
  • 2 GB RAMGEHEUGEN
  • 30 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen

VPS.S3

£11.44 Save  33 %
£7.63 Maandelijks
  • 4 vCPU AMD EPYC
  • 6 GB RAMGEHEUGEN
  • 70 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen

VPS.S4

£15.26 Save  20 %
£12.21 Maandelijks
  • 6 vCPU AMD EPYC
  • 8 GB RAMGEHEUGEN
  • 80 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen

EPYC VPS.P1

£6.86 Save  22 %
£5.34 Maandelijks
  • 2 vCPU AMD EPYC
  • 4 GB RAMGEHEUGEN
  • 40 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

EPYC VPS.P2

£12.97 Save  24 %
£9.92 Maandelijks
  • 2 vCPU AMD EPYC
  • 8 GB RAMGEHEUGEN
  • 80 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

EPYC VPS.P4

£22.90 Save  23 %
£17.55 Maandelijks
  • 4 vCPU AMD EPYC
  • 16 GB RAMGEHEUGEN
  • 160 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

EPYC VPS.P5

£30.53 Save  25 %
£22.90 Maandelijks
  • 8 vCPU AMD EPYC
  • 16 GB RAMGEHEUGEN
  • 180 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

EPYC VPS.P6

£45.80 Save  25 %
£34.35 Maandelijks
  • 8 vCPU AMD EPYC
  • 32 GB RAMGEHEUGEN
  • 200 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

EPYC VPS.P7

£53.44 Save  29 %
£38.17 Maandelijks
  • 16 vCPU AMD EPYC
  • 32 GB RAMGEHEUGEN
  • 240 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

Genoa VPS.G2

£20.61 Save  22 %
£16.03 Maandelijks
  • 2 vCPUAMD EPYC Genoa 4e generatie 9xx4 met 3,25 GHz of vergelijkbaar, op Zen 4-architectuur. AMD EPYC G4
  • 4 GB DDR5GEHEUGEN
  • 50 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

Genoa VPS.G4

£37.40 Save  20 %
£29.77 Maandelijks
  • 4 vCPUAMD EPYC processor met dedicated vCPU cores, op enterprise serverhardware. AMD EPYC G4
  • 8 GB DDR5GEHEUGEN
  • 100 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

Genoa VPS.G6

£74.81 Save  20 %
£59.54 Maandelijks
  • 8 vCPUAMD EPYC processor met dedicated vCPU cores, op enterprise serverhardware. AMD EPYC G4
  • 16 GB DDR5GEHEUGEN
  • 200 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

Genoa VPS.G7

£122.15 Save  22 %
£95.43 Maandelijks
  • 8 vCPUAMD EPYC processor met dedicated vCPU cores, op enterprise serverhardware. AMD EPYC G4
  • 32 GB DDR5GEHEUGEN
  • 250 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland. inbegrepen
  • Gratis auto back-upBevat één back-upslot dat je kunt instellen op dagelijks, wekelijks of maandelijks.

AMD Ryzen VPS.R1

£16.79 Save  18 %
£13.74 Maandelijks
  • 1 dedicated CPU AMD Ryzen 9 7950X met 4,5 GHz of vergelijkbaar, op Zen 4-architectuur. vCPU
  • 4 GB DDR5GEHEUGEN
  • 50 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6 inbegrepen IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland.
  • Auto back-up inbegrepen

AMD Ryzen VPS.R2

£33.59 Save  20 %
£26.71 Maandelijks
  • 2 dedicated CPUs AMD Ryzen 9 7950X met 4,5 GHz of vergelijkbaar, op Zen 4-architectuur. vCPU
  • 8 GB DDR5GEHEUGEN
  • 100 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6 inbegrepen IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland.
  • Auto back-up inbegrepen

AMD Ryzen VPS.R4

£122.15 Save  20 %
£97.72 Maandelijks
  • 8 dedicated CPUs AMD Ryzen 9 7950X met 4,5 GHz of vergelijkbaar, op Zen 4-architectuur. vCPU
  • 32 GB DDR5GEHEUGEN
  • 400 GB NVMeOPSLAG
  • Ongelimiteerde bandbreedte
  • IPv4 & IPv6 inbegrepen IPv6-ondersteuning is momenteel niet beschikbaar in Frankrijk, Finland of Nederland.
  • Auto back-up inbegrepen

*VAT excluded.

INCLUDED WITH EVERY PLAN

✓ No setup fees ✓1 Gbps network
✓ Full root access on KVM ✓ Free server monitoring ✓ Firewall management ✓24/7 support

mod_crowdsec with .htaccess, PHP, ModSecurity and Basic auth

.htaccess

The directives aren't allowed there. A Crowdsec On line in .htaccess turns the whole directory into a 500, with "Crowdsec not allowed here" in the error log. Put them in the vhost or in a <Directory> block in the server config.

Apache error.log alert: /var/www/html/.htaccess: Crowdsec not allowed here

The error log names the cause of the 500: the directive isn't allowed in .htaccess.

mpm_event with PHP-FPM and prefork with mod_php

Both worked: the challenge was served and submitted, AppSec blocked /.env, stream mode stayed primed and the error log stayed clean. Ubuntu's default is event with PHP-FPM, and that's the one I'd keep.

ModSecurity on the same server

mod_crowdsec runs first, in the access phase, ahead of ModSecurity's request rules. A request CrowdSec blocks never reaches ModSecurity, and neither does a challenged one. When CrowdSec lets a request through, ModSecurity still inspects it: a SQL injection on a path exempt from the challenge passed CrowdSec (with an out-of-band CRS alert) and was then blocked by ModSecurity's own CRS. That's one block with two log entries, and no request got a 403 from both. Running both during a transition is safe, and once the CrowdSec CRS alerts line up with what ModSecurity blocks, I'd retire ModSecurity.

Basic auth

GitHub issues #14 and #17 report Basic auth breaking under the 0.1 module, including a bare 401 with no WWW-Authenticate header. On rc2 the 401 carried its header every time. With bot detection on, the challenge comes before the 401, so the password prompt only appears once the challenge is passed. On a path with AppSec off, the 401 arrives without the challenge. A banned IP gets a 401 on that path as well, which can make a ban look like a password problem. I didn't test a full login through the challenge.

Redirects

Issues #8 and #13 describe broken redirects and 301s without a Location header on 0.1. On rc2 a Redirect 301 /old /new kept its Location header and wasn't challenged. A banned IP still gets the 301, because mod_alias answers before the access check runs, and the target page then blocks it.

Apache behind a reverse proxy or Cloudflare

Behind Cloudflare, a load balancer or a local proxy, the module sees the proxy's address unless mod_remoteip restores the client's. List only the proxy's addresses with RemoteIPInternalProxy or RemoteIPTrustedProxy. In my test a banned client coming through the trusted proxy got a 403, and a spoofed X-Forwarded-For sent straight to Apache was ignored. CrowdsecTrustUseragentIP Off makes the module check the connecting address instead, which behind a proxy means every visitor is judged by the proxy's IP.

Fix the conffile prompt when upgrading mod_crowdsec

The API key sits in the package's own conffile, so an upgrade that changes the shipped file stops to ask if you want to keep your modified crowdsec-apache2-bouncer.conf. Going from rc1 to rc2 did exactly that. Run unattended, dpkg gives up with "end of file on stdin at conffile prompt" and leaves the package half-configured. Finish the install and keep your file:

sudo dpkg --configure -a --force-confold

Keeping your file keeps the key, and the old release's settings with it. rc1's file had a bare CrowdsecCache shmcb and its AppSec example inside <Location />. rc2's version lands next to yours as crowdsec-apache2-bouncer.conf.dpkg-dist, so diff the two and copy across what changed:

sudo diff /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf /etc/crowdsec/bouncers/crowdsec-apache2-bouncer.conf.dpkg-dist

One more thing to know before you reach for apt purge: it removes the bouncer's registration along with the config, and a reinstall registers a new bouncer with a new key.

Questions?

Is Crowdsec On or Off by default in mod_crowdsec?

Both, depending on where you look. The directive defaults to Off, and the config file the package installs sets Crowdsec On at server level, so a package install enforces decisions as soon as Apache restarts. That's the mismatch GitHub issue #11 on the bouncer's repository describes. A build from source with a minimal config enforces nothing until you add the line yourself.

Ellie Grace Hayes
About the author

Ellie Grace Hayes

I grew up in Minnesota and started working remotely before I decided that travelling was going to become a permanent part of my life. And it kinda did, more or less... I tend to stay somewhere for a month or two, sometimes longer if I like the place (so "digital nomad" is technically accurate, even if most days are much less exciting than the term suggests). Usually I'm at a desk in a rented room trying to work out why a command behaved differently on two supposedly identical machines :)

I came into technical writing through support work & community tutorials. Linux was the first subject I wrote about, but since then I've wandered into containers, hosting, networking plus a lot of self-hosted software. I've played Minecraft since I was a kid and still go through phases where I get completely absorbed in it for a few weeks. I don't have a five-year plan. I've tried - it keeps becoming a six-month plan instead.

Deploy your next project in seconds

Bring your winning ideas online faster, with modern hardware and unmetered bandwidth. Join a European cloud trusted by thousands of developers and businesses worldwide.