> ## Content Index
> Fetch the complete content index at: https://corelab.tech/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Deploy CrowdSec AppSec (WAF) with SWAG in Docker
- URL: https://corelab.tech/crowsec-waf-swag-docker/
- Published: 2026-09-18T15:26:51.000Z
- Updated: 2026-11-17T15:03:31.000Z
- Description: Learn how to successfully deploy CrowdSec's Web Application Firewall behind a LinuxServer SWAG reverse proxy across a Docker Macvlan without getting 'connection refused' errors.
- Author: Core Lab Joe
- Tags: CrowdSec, SWAG, Docker, Cybersecurity, #2026, #table-of-content

## Why the Official CrowdSec Docs Break in a Docker Macvlan/IPvlan

Deploying CrowdSec's Web Application Firewall (AppSec) behind a LinuxServer SWAG (Nginx) reverse proxy is a great way to automatically block exploit payloads. However, if you are running them in separate Docker containers on a Macvlan or IPvlan network, following the official CrowdSec documentation *verbatim* will leave you with a bouncer that ***silently skips the WAF entirely*** or crashes with "connection refused" errors.

Here is how to properly configure the LinuxServer `swag-crowdsec` Mod and the CrowdSec AppSec engine to communicate across your Docker network, avoiding the undocumented pitfalls.

---

Learning Path • Reverse Proxy & Ingress 

### Mastering Reverse Proxies with SWAG 

Deploy SWAG in Docker, configure Let's Encrypt certificates, harden NGINX against scanner leaks, integrate centralized Authelia MFA, and enforce Layer 7 CrowdSec AppSec (WAF) defence. 

Lesson 6 of 6 100% Complete 

Difficulty Curve Advanced 

Beginner Advanced 

[ ✓ Lesson 01 · Foundations Completed What is a Reverse Proxy? Why Every Homelab Needs One → ](https://corelab.tech/what-is-a-reverse-proxy/) [ ✓ Lesson 02 · Core Deployment Completed Self-Hosting SWAG: Deploying Your Reverse Proxy in Docker → ](https://corelab.tech/swag-reverse-proxy-guide/) [ ✓ Lesson 03 · Zero-Trust Ingress Completed Hardening SWAG: How I Killed Default Server Fingerprinting and Subdomain Leaks → ](https://corelab.tech/hardening-swag-reverse-proxy-fingerprinting/) [ ✓ Lesson 04 · Identity & MFA Completed Authelia: Centralized MFA for Self-Hosted Services → ](https://corelab.tech/authelia-mfa-swag-setup/) [ ✓ Lesson 05 · Threat Defence Completed CrowdSec & Fail2Ban: Real-Time Threat Defence for SWAG → ](https://corelab.tech/crowdsec-fail2ban-swag-hardening/) 

06 

Lesson 06 · Application Security Current Lesson 

How to Deploy CrowdSec AppSec (WAF) with SWAG in Docker 

Tested in production on Linux & Docker CE 

Core Lab Learning Track · Zero Tracking & Direct Implementation 

---

## Pre-Requisites:

1. Existing [installation of SWAG](https://corelab.tech/swag-reverse-proxy-guide/) and;

[Self-Hosting SWAG: NGINX Reverse Proxy Guide (2026)Forget Nginx Proxy Manager. Learn how to set up LinuxServer.io SWAG with CrowdSec, Authelia, and the new Dashboard Mod for a secure, automated reverse proxy stack.![](https://corelab.tech/content/images/icon/Glowing_CPU-1-7c2b4b90-5a2c-4f9a-8bcc-d5621381af65.png)Core LabCore Lab Joe![](https://corelab.tech/content/images/thumbnail/SWAG-Banner-69b7188d-dd20-42ce-89f3-543a16e17c96.webp)](https://corelab.tech/swag-reverse-proxy-guide/)

1. Existing [installation of CrowdSec](https://corelab.tech/crowdsec-fail2ban-swag-hardening/).

[CrowdSec & Fail2Ban: Real-Time SWAG Threat Defense (2026)Stop brute-force attacks and secure your self-hosted apps. Learn to deploy harden SWAG with CrowdSec for an A+ security rating and Zero Trust access.![](https://corelab.tech/content/images/icon/Glowing_CPU-1-0bcbb03f-ce60-49c9-822c-65d4f48a898e.png)Core LabCore Lab Joe![](https://corelab.tech/content/images/thumbnail/Digital-Fortress-3ba6d244-4084-498f-8d33-5b809b0a10fb.webp)](https://corelab.tech/crowdsec-fail2ban-swag-hardening/)

---

## 1\. Fixing the SWAG Bouncer: Injecting the CROWDSEC\_APPSEC\_URL Variable

The official [CrowdSec documentation](https://docs.crowdsec.net/docs/next/appsec/quickstart/nginxopenresty/?ref=corelab.tech) instructs you to manually edit `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` and add your `APPSEC_URL`. **Do not do this in SWAG!**

The [LinuxServer CrowdSec Docker Mod](https://github.com/linuxserver/docker-mods/tree/swag-crowdsec?ref=corelab.tech) executes an initialization script on every boot that aggressively strips the `APPSEC_URL` string from the configuration file if a specific Docker environment variable is missing. This will silently disable your WAF after every restart. 

To fix this, you must inject the URL directly into your SWAG `compose.yaml` environment block:

```yaml
services:
  swag:
    image: lscr.io/linuxserver/swag:latest
    environment:
      - DOCKER_MODS=linuxserver/mods:swag-crowdsec
      # Other variables...
      - CROWDSEC_API_KEY=your_bouncer_key_here
      - CROWDSEC_LAPI_URL=http://10.0.0.5:8080
      - CROWDSEC_APPSEC_URL=http://10.0.0.5:7422

```

📡

****WTF is Happening?!**  
  
You're simply telling SWAG that you've turned on CrowdSec WAF, and your bouncer will now accept the variable to reach it on a new port `[7422]`.

---

## 2\. Solving "Connection Refused": Changing the AppSec Listen Address

By default, CrowdSec's AppSec component is configured to listen on `127.0.0.1:7422`. The official documentation explicitly warns you to "Keep listen\_addr on 127.0.0.1" for security reasons.

While this is true for bare-metal deployments where Nginx and CrowdSec share the same host, it completely breaks Docker deployments where SWAG and CrowdSec are **in separate containers (**which is the standard deployment with SWAG & CrowdSec). SWAG cannot reach `127.0.0.1` inside the CrowdSec container.

You must modify your CrowdSec AppSec acquisition file to listen on all interfaces (`0.0.0.0`). There's a warning in the official docs about this, but if you configured your CrowdSec container correctly, it only has 1 interface and only talks to SWAG anyway.

Edit `/config/acquis.d/appsec.yaml` inside your CrowdSec container (or mapped volume):

```yaml
appsec_configs:
  - crowdsecurity/appsec-default
labels:
  type: appsec
listen_addr: 0.0.0.0:7422
source: appsec

```

![Screenshot showing Core Lab's own live appsec.yaml config file.](https://corelab.tech/content/images/2026/09/CrowdSec-WAF-appsec-config.webp)

Here's my live config, I use now.

---

## 3\. Installing CrowdSec Virtual Patching Rules for the WAF

Before the WAF can block anything, you need to install the virtual patching rules inside the CrowdSec container. Add these to your existing crowdsec container `COLLECTIONS` variable:

```bash
- COLLECTIONS=crowdsecurity/nginx crowdsecurity/base-http-scenarios crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules crowdsecurity/whitelist-good-actors
```

Restart the CrowdSec container first to bind to `0.0.0.0:7422`, and then restart your SWAG container so the bouncer picks up the environment variable.

`docker compose restart crowdsec && docker logs -f crowdsec`

Watch the logs and you'll see it download & install the new collections, `CTRL-C` to cancel out. Then SWAG:

`docker compose restart swag && docker logs -f swag` and watch it fire up. It can take a few minutes to download all your mods/configs.

---

## 4\. Testing the CrowdSec WAF with an External XSS Payload

To verify the setup is working, you need to trigger a rule. Keep in mind that CrowdSec automatically whitelists private LAN IP ranges (like `10.0.0.x` or `192.168.x.x`). If you test from your local network or a VPN split tunnel, you will get a `200 OK` response, falsely leading you to believe the WAF is broken.

Disconnect from your VPN and test from an external connection (like a cellular network) using `curl` or a browser:

```bash
curl -I https://yourdomain.com/.env

```

If configured correctly, the AppSec engine will intercept the request and return the HTML ban page with a `403 Forbidden` status.

Finally, check your internal metrics to confirm the AppSec engine is processing and blocking payloads:

```bash
docker exec crowdsec cscli metrics show appsec

```

---

#### Join the Core Lab Inner Circle

If this saved you hours of troubleshooting, subscribe to the CoreLab newsletter so you don't miss the next deep-dive!

[Join Now](#/portal/signup) 

---

## What's Next?

Did you want to advance your security further? Jump on over to my [OPNsense Master Series](https://corelab.tech/opnsensept1/) and gain advanced threat protection & defence right at your perimeter!

[OPNsense 26.2 Master Guide: Architecture, Hardware & Deployment (2026)Master OPNsense firewall setup. Build a digital fortress with OPNsense 26.2\. This expert 2026 guide covers network topology, hardware sizing, ZFS installation, DNS config and baseline systems hardening.![](https://corelab.tech/content/images/icon/Glowing_CPU-1-45fe1092-941c-4862-b200-136015bc10f3.png)Core LabCore Lab Joe![](https://corelab.tech/content/images/thumbnail/opnsense_blueprint_hero_1788452624572-1d3782a5-c33e-4fe8-91e0-825c3e2f6f14.jpg)](https://corelab.tech/opnsensept1/)

---

## Frequently Asked Questions

### Why does CrowdSec AppSec return "connection refused" in Docker?

This happens when the CrowdSec WAF engine is bound to `127.0.0.1` (localhost). In a Docker environment where SWAG and CrowdSec run in separate containers, SWAG cannot reach CrowdSec's localhost. You must change the `listen_addr` to `0.0.0.0:7422` in your `appsec.yaml` configuration.

### Why does the LinuxServer SWAG CrowdSec mod wipe my APPSEC\_URL config?

The official `swag-crowdsec` Docker Mod runs an initialization script on every boot that deletes the `APPSEC_URL` variable if the `CROWDSEC_APPSEC_URL` environment variable is not defined in your Docker Compose file. To make the setting persistent, define the URL directly in your `compose.yaml` instead of manually editing the bouncer configuration file.

### How do I test if my CrowdSec WAF is working?

You can test your WAF by sending a common exploit payload (like an XSS script or a `.env` file request) to your web server using curl. However, make sure you test from an external network (like a cellular connection), because CrowdSec automatically whitelists private LAN IP ranges (such as `10.0.x.x` and `192.168.x.x`).