# crowdsecurity/cs-nginx-bouncer architecture

> Architecture diagram of the GitHub repository crowdsecurity/cs-nginx-bouncer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crowdsecurity/cs-nginx-bouncer
- Repository: https://github.com/crowdsecurity/cs-nginx-bouncer

## Overview

CrowdSec NGINX Bouncer is a Lua access-control bouncer for NGINX. A request enters NGINX’s `access_by_lua_file` hook, where the bouncer checks new or unknown IPs against the CrowdSec API; requests deemed blocked receive HTTP 403, and the block is cached. The README also identifies the CrowdSec Lua library as the bouncer’s backend. Source excerpts were unavailable, so these relationships are based on README statements; internal implementation details and cache behavior beyond the documented write are not inferred.

Main entry points: [`nginx/crowdsec_nginx.conf`](https://github.com/crowdsecurity/cs-nginx-bouncer/blob/main/nginx/crowdsec_nginx.conf) (Lua access hook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Request entry"]
  node_nginx["NGINX"]
  node_access_hook["Lua access hook"]
  node_response["HTTP response"]
end

subgraph group_decision["Block decision"]
  node_lua_bouncer["CrowdSec Lua bouncer"]
  node_crowdsec_api["CrowdSec API"]
  node_block_cache["Block cache"]
  node_lua_library["CrowdSec Lua library"]
end

node_client(("Request client"))

node_client -->|"sends request"| node_nginx
node_nginx -->|"runs access hook"| node_access_hook
node_access_hook -->|"invokes bouncer"| node_lua_bouncer
node_lua_bouncer -->|"checks IP"| node_crowdsec_api
node_lua_bouncer -->|"caches block"| node_block_cache
node_lua_bouncer -->|"returns 403"| node_response
node_lua_bouncer -->|"uses library"| node_lua_library

click node_access_hook "https://github.com/crowdsecurity/cs-nginx-bouncer/blob/main/nginx/crowdsec_nginx.conf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nginx,node_access_hook,node_response,node_client toneBlue
class node_lua_bouncer,node_crowdsec_api,node_block_cache,node_lua_library toneAmber
```

## Components

### Request entry

- **NGINX**
- [Lua access hook](https://github.com/crowdsecurity/cs-nginx-bouncer/blob/main/nginx/crowdsec_nginx.conf): `nginx/crowdsec_nginx.conf`
- **HTTP response**

### Block decision

- **CrowdSec Lua bouncer**
- **CrowdSec API**
- **Block cache**
- **CrowdSec Lua library**

### Other components

- **Request client**

## Connections

- Request client → NGINX: sends request (evidence: `README.md`)
- NGINX → Lua access hook: runs access hook (evidence: `README.md`)
- Lua access hook → CrowdSec Lua bouncer: invokes bouncer (evidence: `README.md`)
- CrowdSec Lua bouncer → CrowdSec API: checks IP (evidence: `README.md`)
- CrowdSec Lua bouncer → Block cache: caches block (evidence: `README.md`)
- CrowdSec Lua bouncer → HTTP response: returns 403 (evidence: `README.md`)
- CrowdSec Lua bouncer → CrowdSec Lua library: uses library (evidence: `README.md`)
