Comprehensive VPS Security: Guide to Deploying Coraza WAF with Traefik v3 Reverse Proxy
This guide details deploying Coraza WAF, an open-source web application firewall based on NGINX, combined with Traefik v3 as a reverse proxy to protect VPS from L7 attacks such as...
This guide details deploying Coraza WAF, an open-source web application firewall based on NGINX, combined with Traefik v3 as a reverse proxy to protect VPS from L7 attacks such as SQL injection, XSS, and OWASP Top 10 vulnerabilities. It provides a full Docker Compose configuration, automatic HTTPS routing, and WAF integration into web traffic for effective and easy VPS infrastructure security.
Introduction to Coraza WAF and Traefik v3
Coraza WAF is an open-source security solution compatible with ModSecurity, designed to integrate into web servers and reverse proxies like NGINX, Apache, or Traefik. With the ability to inspect and block malicious HTTP requests based on OWASP rules, Coraza helps protect web applications from common attacks. Traefik v3 is a modern reverse proxy that supports automatic routing, integrates Let's Encrypt for free SSL certificate issuance, and scales easily in container environments.
Combining Coraza WAF with Traefik v3 creates a comprehensive security system: Traefik manages access and routing, while Coraza acts as an additional application-layer inspection layer, blocking dangerous requests before they reach the origin application. This deployment approach is ideal for VPS environments using Docker, especially when protecting web applications that lack built-in WAF capabilities.
Requirements and Preparation
To deploy this solution, you need:
- A Linux-based VPS (Ubuntu 20.04/22.04 or Debian 11/12)
- Docker and Docker Compose installed
- A domain name pointing to your VPS IP address
- SSH access to the VPS
Ensure ports 80 (HTTP) and 443 (HTTPS) on your VPS are open and not blocked by the system firewall or hosting provider. If you use DPTCloud VPS, you can leverage the network security and 99.98% SLA infrastructure to enhance L3/L4 protection before traffic reaches your application.
Deploying Coraza WAF with Traefik v3
Follow these steps to configure and deploy the system:
1. Create a working directory:
mkdir -p /opt/coraza-traefik
cd /opt/coraza-traefik
2. Create a docker-compose.yml file with the following configuration:
version: '3.8'
services:
traefik:
image: traefik:3
container_name: traefik
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.yml:/traefik.yml:ro
- ./certs:/certs
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.example.com`)"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
restart: unless-stopped
coraza:
image: coraza/waf:latest
container_name: coraza-waf
ports:
- "8080:8080"
volumes:
- ./rules:/rules
- ./coraza.conf:/coraza.conf
environment:
- CORAZA_RULES_PATH=/rules
- CORAZA_CONFIG_PATH=/coraza.conf
restart: unless-stopped
app:
image: nginx:alpine
container_name: app
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`app.example.com`)"
- "traefik.http.routers.app.entrypoints=websecure"
- "traefik.http.routers.app.tls.certresolver=letsencrypt"
restart: unless-stopped
3. Create a traefik.yml file to configure Traefik:
entryPoints:
web:
address: ':80'
websecure:
address: ':443'
certificatesResolvers:
letsencrypt:
acme:
email: [email protected]
storage: /certs/acme.json
caServer: https://acme-v02.api.letsencrypt.org/directory
keyType: ECDHE-ECDSA
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
4. Create a coraza.conf file to configure Coraza:
SecRuleEngine On
SecRequestBodyAccess On
SecRule REQUEST_URI "@streq /wp-admin" "id:1001,phase:1,deny,status:403,msg:'WordPress admin blocked'"
SecRule REQUEST_HEADERS:User-Agent "@streq curl" "id:1002,phase:1,deny,status:403,msg:'User-Agent curl blocked'"
5. Create a rules directory and add custom OWASP rules if needed. You can reference rules from Integrating Coraza WAF into Caddy Web Server: Steel Shield Against OWASP Top 10 Attacks.
6. Run the command:
docker-compose up -d
After execution, Traefik will automatically issue SSL certificates for defined domains, and Coraza WAF will begin inspecting HTTP requests to the application.
Verification and Testing
To verify the system is working correctly:
- Access
https://app.example.comin a browser and confirm the website loads properly. - Run the following command from a local machine:
curl -H "User-Agent: curl" https://app.example.com
If configured correctly, you will receive a 403 (Forbidden) status code due to the Coraza rule blocking the "curl" User-Agent.
To test if Coraza WAF is active, add a simple test rule and attempt to access an invalid URL.
Troubleshooting
If you cannot access the application:
- Check Traefik logs:
docker logs traefik - Check Coraza WAF logs:
docker logs coraza-waf - Ensure domain names are correctly pointed to your VPS IP and ports 80/443 are not blocked.
- Review
traefik.ymlanddocker-compose.ymlfor syntax errors.
For SSL certificate issues, check the acme.json file and ensure proper file permissions.
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
