Illustrative WIUNIX Academy IT engineering workspace with server/network equipment and an instructional board: CrowdSec and Nginx: trustworthy logs, private LAPI and reversible IP bans

WIUNIX ACADEMY

CrowdSec and Nginx: trustworthy logs, private LAPI and reversible IP bans

Build an isolated CrowdSec 1.8.2 and Lua bouncer 1.2.3 lab on DEB, RHEL-family or Arch-family Linux; check HTTP bans, recovery and API outages.

Intermediate55 min readUpdated
Make this guide yours

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

RHEL 10.2 · standard channelReviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment7 editable values

THE OUTCOME

What will you have at the end?

Verify a complete local decision-to-HTTP enforcement path.

01Nginx127.0.0.1:18080 → access log
02Engine → LAPI/srv/academy-crowdsec · 127.0.0.1:18081
03Lua bounceracademy_nginx · ban/allow 127.0.0.2
Supported operating systems and versions

Documented Linux paths reviewed 2026-11-05; historical fixture tests do not certify the updated runtime or production deployment.

Before you begin

  • Fresh disposable x86_64 VM with sudo, internet and disk space; RHEL/Arch selections build OpenResty locally.
  • Linux/Nginx familiarity, two terminals and an independent recovery console; no production traffic.

Make detection and enforcement observable

Build a loopback-only CrowdSec/Nginx lab under /srv/academy-crowdsec. Security Engine 1.8.2 reads conventional Nginx logs, a local SQLite-backed API stores decisions, and Lua bouncer 1.2.3 checks each request source. This is an isolated exercise before a separately designed production rollout.

Allow about55 minutes after prerequisites. You will distinguish parsed logs from scenario alerts and from actual HTTP403 enforcement, then verify unban, expiry, spoofed headers and API outage behavior. Installing the engine alone does not protect Nginx. IP reputation is defense in depth alongside authentication, patching and application rate limits.

Edit public values, Apply, then copy

Open the collapsed settings, edit public values, press Apply, then copy. Pending or invalid changes disable copy buttons. Never put an API key, password, private key or log containing personal data into this form. The bouncer key is generated inside a protected process and written straight to a private file.

Settings and custom progress use sessionStorage for this tab/language/article/environment; default progress uses localStorage. Reset restores reviewed defaults. Changing text does not execute a test or reserve a port. 127.0.0.2 must remain a loopback source distinct from the trusted management CIDR 127.0.0.1/32; the preflight validates that additional relationship.

Use an empty amd64 VM and matching Lua packages

Use a fresh disposable sudo-enabled x86_64 VM; the engine archive contains Linux amd64 executables. Ubuntu 26.10 is the default, with Ubuntu 26.04/24.04 and Debian 13/12 distribution Nginx/Lua paths. Do not combine a module built for a distribution Nginx ABI with an nginx.org binary.

RHEL, Rocky and Alma 10.2/9.8 and Arch/Manjaro rolling selections reviewed 2026-11-05 build OpenResty 1.31.8.1 exclusively under this lab root. OpenResty bundles Nginx, LuaJIT and matching modules; this does not claim a compatible distro Lua RPM or official CrowdSec certification for every OS. Rolling systems have a review date, not an invented fixed release.

Existing web/security installation guards refuse prior configuration, executables or system units. Use another fresh VM instead of bypassing them. DEB package installation may start distribution Nginx: the disposable VM must have no public ingress. The lab child, LAPI and metrics listen only on loopback. No firewall rule, public TLS, Console/CAPI enrollment, CAPTCHA or AppSec is enabled.

01

LET’S BUILD

Install distribution Nginx and Lua dependencies

Use only the fresh disposable VM. Refuse existing Nginx/CrowdSec files and units before the package manager can change them. Review the selected package candidates; missing or incompatible packages stop this path. DEB installs matched distribution Nginx/Lua; RHEL and Arch install build prerequisites for the later private OpenResty build. Package availability is not a CrowdSec support guarantee.

bash

Dedicated disposable VM · terminal

set -eu
. /etc/os-release
test "$ID" = 'rhel'
test "$VERSION_ID" = '10.2'
for p in /etc/nginx /etc/crowdsec /usr/local/openresty /usr/sbin/nginx /usr/bin/nginx /usr/bin/crowdsec /usr/sbin/crowdsec /usr/bin/cscli; do
    if test -e "$p" || test -L "$p"; then
        echo "Existing web/security path: $p; use a fresh VM" >&2; exit 1
    fi
done
for name in nginx openresty crowdsec cscli; do
    if command -v "$name" >/dev/null 2>&1; then
        echo "Existing executable: $name; use a fresh VM" >&2; exit 1
    fi
done
states=$(sudo systemctl show nginx.service crowdsec.service -p LoadState --value)
for state in $states; do
    test "$state" = not-found || { echo 'Existing or masked system service; use a fresh VM' >&2; exit 1; }
done
sudo subscription-manager repos --enable codeready-builder-for-rhel-10-x86_64-rpms
sudo dnf info gcc make perl pcre2-devel openssl-devel zlib-devel python3 python3-pyyaml
sudo dnf install gcc make perl pcre2-devel openssl-devel zlib-devel python3 python3-pyyaml curl ca-certificates nano tar gzip shadow-utils
rpm -q gcc pcre2-devel openssl-devel zlib-devel python3
How do I know it worked?

Selected dependencies are installed and actual versions appear; unavailable repositories or packages stop this path.

02

LET’S BUILD

Check architecture, ports and management separation

Keep 127.0.0.2 in127/8; the source is only meaningful on this VM. Use 127.0.0.1/32 only for the actual local management address, not a whole visitor network.

The management request binds 127.0.0.1; the management CIDR must stay within 127/8 and include that address while excluding the test source.

bash

Dedicated disposable VM · terminal

set -eu
test "$(uname -m)" = x86_64
sudo python3 - <<'PY'
import socket,ipaddress
ip=ipaddress.ip_address('127.0.0.2')
if ip not in ipaddress.ip_network('127.0.0.0/8'):
    raise SystemExit('Test source must be loopback')
management=ipaddress.ip_network('127.0.0.1/32')
if not management.subnet_of(ipaddress.ip_network('127.0.0.0/8')) or ipaddress.ip_address('127.0.0.1') not in management:
    raise SystemExit('Management must be a loopback CIDR containing 127.0.0.1')
if ip in management:
    raise SystemExit('Test source is allowlisted')
for port in (18080,18081,18082):
    with socket.socket() as s: s.bind(('127.0.0.1',port))
print('amd64, separate free ports and test source: OK')
PY
How do I know it worked?

The check prints OK without opening a persistent listener; busy ports or an allowlisted test source stop it.

03

LET’S BUILD

Reserve one private root without overwriting files

Create a dedicated worker identity and one new root. The parent ancestry must already be root-owned, non-writable by others and contain no symlink. Existing roots or the same worker identity are refused. Config/data remain private; workers need only traversal and the readable static file. Explicit modes prevent a restrictive inherited umask from making the test page unreadable. Use a fresh VM after investigating a partial attempt.

bash

Dedicated disposable VM · terminal

sudo python3 - <<'PY'
import os,stat,grp,pwd,subprocess
from pathlib import Path
r=Path('/srv/academy-crowdsec')
if not r.is_absolute() or str(r) in ('/','/srv','/opt','/etc','/tmp'):
    raise SystemExit('Choose a new dedicated child directory')
for p in reversed(r.parents):
    m=p.lstat()
    if not stat.S_ISDIR(m.st_mode) or m.st_uid!=0 or m.st_mode & 0o022:
        raise SystemExit('Unsafe parent: '+str(p))
for fn in (pwd.getpwnam,grp.getgrnam):
    try: fn('academy-crowdsec')
    except KeyError: pass
    else: raise SystemExit('Lab identity already exists; use a fresh VM')
r.mkdir(mode=0o750)
subprocess.run(['useradd','--system','--user-group','--no-create-home',
                '--shell','/usr/sbin/nologin','academy-crowdsec'],check=True)
os.chown(r,0,grp.getgrnam('academy-crowdsec').gr_gid)
os.chmod(r,0o750)
for name in ('downloads','config','data','hub','logs','run','www','notifications','plugins'):
    p=r/name;p.mkdir(mode=0o700 if name in ('config','data') else 0o755)
    os.chmod(p,0o700 if name in ('config','data') else 0o755)
(r/'www'/'index.html').write_text('academy-ok\n',encoding='utf-8')
os.chmod(r/'www'/'index.html',0o644)
for name in ('engine.yaml','acquis.yaml','profiles.yaml','simulation.yaml','nginx.conf'):
    fd=os.open(r/'config'/name,os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,0o600);os.close(fd)
print('Exclusive lab root, worker identity and empty editor files created')
PY
How do I know it worked?

Exclusive lab root, dedicated worker identity and empty editor files exist; repeat execution refuses prior state.

Explore all tutorials ↗