# Bunkerized NGINX

> NGINX Docker image secure by default with built-in security features.

- Category: Web Servers & Reverse Proxies
- Difficulty: beginner
- Components: bunkerized-nginx
- Tags: nginx, security, hardened, waf, docker
- Source: https://docker.recipes/web-servers/bunkerized-nginx

## Overview

Bunkerized NGINX is a security-hardened Docker image that transforms the popular NGINX web server into a comprehensive security solution by integrating Web Application Firewall (WAF) capabilities, anti-bot protection, and security headers management. Built on top of NGINX's proven high-performance architecture, this container combines NGINX's efficient reverse proxy functionality with ModSecurity WAF rules, bad behavior detection, and automatic security hardening measures that typically require manual configuration and ongoing maintenance.

This security-first approach addresses the growing need for web applications to defend against automated attacks, bot traffic, and common web vulnerabilities without requiring extensive security expertise. The container automatically applies OWASP ModSecurity Core Rule Set, implements rate limiting based on behavioral analysis, and provides real-time threat detection while maintaining NGINX's performance characteristics for legitimate traffic.

This solution is ideal for developers and system administrators who need production-ready web server security without the complexity of manually configuring and maintaining separate WAF solutions, security rule updates, and threat intelligence feeds. Organizations running public-facing applications, API endpoints, or content delivery networks can deploy comprehensive web security protection with minimal configuration overhead.

## Features

- ModSecurity Web Application Firewall with OWASP Core Rule Set integration
- Behavioral-based bad bot detection and automatic IP blocking
- Real-time security headers injection including CSP, HSTS, and X-Frame-Options
- Automatic Let's Encrypt SSL certificate provisioning and renewal
- Anti-bot challenge system with JavaScript verification and CAPTCHA
- Geographic IP filtering and country-based access control
- Rate limiting with burst protection and sliding window algorithms
- Automatic security rule updates and threat intelligence feed integration

## Use cases

- E-commerce websites requiring PCI compliance and fraud protection
- API endpoints needing protection from automated scraping and abuse
- Content management systems vulnerable to common web attacks
- SaaS applications requiring multi-tenant security isolation
- Development teams needing security-by-default in CI/CD pipelines
- Small businesses lacking dedicated security teams but needing enterprise-grade protection
- Reverse proxy deployments for microservices requiring centralized security policy

## Prerequisites

- Docker Engine 20.10+ and Docker Compose v2 for container orchestration
- Minimum 512MB RAM allocated to container for ModSecurity rule processing
- Ports 80 and 443 available on host system for HTTP/HTTPS traffic
- Valid domain name configured in DNS for Let's Encrypt SSL certificates
- Basic understanding of NGINX configuration for custom rule modifications
- Network connectivity for automatic security rule updates and threat feeds

## docker-compose.yml

```yaml
services:
  bunkerized-nginx:
    image: bunkerity/bunkerweb:latest
    container_name: bunkerweb
    restart: unless-stopped
    environment:
      SERVER_NAME: localhost
      AUTO_LETS_ENCRYPT: "no"
      USE_MODSECURITY: "yes"
      USE_BAD_BEHAVIOR: "yes"
    ports:
      - "80:8080"
      - "443:8443"
    networks:
      - bunker-network

networks:
  bunker-network:
    driver: bridge
```

## .env

```bash
SERVER_NAME=localhost
AUTO_LETS_ENCRYPT=no
```

## Usage notes

- Docs: https://docs.bunkerweb.io/
- Security features enabled by default - ModSecurity WAF, bad bot blocking
- Set SERVER_NAME to your domain for proper SSL with Let's Encrypt
- Auto Let's Encrypt: set AUTO_LETS_ENCRYPT=yes
- Security headers, rate limiting, antibot challenge automatically applied
- Whitelist IPs with WHITELIST_IP env var if needed

## Troubleshooting

- ModSecurity blocking legitimate traffic: Adjust USE_MODSECURITY_CRS environment variable or whitelist specific IP ranges with WHITELIST_IP
- Let's Encrypt certificate generation failing: Verify SERVER_NAME matches actual domain and ports 80/443 are accessible from internet
- High CPU usage during bot attacks: Enable USE_ANTIBOT=yes and configure ANTIBOT_AUTO_BLOCK_TIME for automatic mitigation
- WebSocket connections being dropped: Set USE_MODSECURITY_SEC_AUDIT_LOG=no to reduce processing overhead for real-time connections
- Custom application returning 403 errors: Review ModSecurity audit logs and add application-specific rules using CUSTOM_CONF_SERVER_HTTP
- Container failing to start with permission errors: Ensure Docker daemon has proper file system permissions and SELinux contexts if enabled

