Nginx Proxy GuardNginx Proxy Guard

Security Hardening

Defend against brute-force and DDoS attacks using Rate Limiting and Fail2ban.

Rate Limiting

Protect the server from excessive traffic by limiting the request rate.

Configuration Options

OptionDescriptionDefault
Requests Per Second (RPS)Maximum requests allowed per second10
Burst SizeAllowance for momentary traffic spikes20
Limit ModeIP, URI, IP+URIIP
Response CodeResponse returned when the limit is exceeded429

Limit Modes

ModeDescriptionWhen to Use
IP-basedLimit per client IPGeneral use
URI-basedLimit per request pathProtecting API endpoints
IP+URICombination of IP and URIFine-grained control

Whitelisted IPs

Configure IPs that bypass Rate Limiting.

  • Trusted internal IPs
  • Monitoring system IPs
  • Partner company IPs

Fail2ban Integration

Automatically block IPs based on failed requests.

Configuration Options

OptionDescriptionDefault
Max RetriesNumber of failures allowed before blocking5
Detection WindowPeriod over which failures are aggregated600s
Ban DurationHow long an IP stays blocked3600s
Trigger Status CodesStatus codes considered failures401, 403

How It Works

  1. The client receives a response with a configured status code
  2. Failures are aggregated within the detection window
  3. The IP is automatically blocked once max retries is exceeded
  4. The block is automatically lifted after the ban duration

Ban Types

TypeDescription
Temporary BanAutomatically lifted after the configured duration
Permanent BanRequires manual removal

IP Block Management

Blocked IP List

  • View all currently blocked IPs
  • Block source (Fail2ban, WAF, manual)
  • Block time and expiration time
  • Block reason

Manual IP Blocking

  • Block an individual IP or CIDR range
  • Permanent ban option
  • Record block notes

IP Block History

All ban/unban events are recorded.

FieldDescription
TimeTime the event occurred
IPTarget IP address
Actionban or unban
Sourcefail2ban, waf_auto_ban, manual, api, expired
ReasonBlock reason

Block Statistics

  • Total number of blocks
  • Block distribution by source
  • Block trends over time
  • Block history for a specific IP

URI Blocking

Block access to specific URI patterns.

Per-Host URI Blocking

Configure independent URI blocking rules for each proxy host.

  • Regular expression pattern support
  • Wildcard support
  • Priority configuration

Global URI Blocking

URI blocking rules applied commonly across all hosts.

  • Block security vulnerability paths
  • Protect admin pages
  • Block access to sensitive files

URI Blocking Examples

# WordPress admin protection
/wp-admin/*
/wp-login.php

# Block sensitive files
/.env
/.git/*
/config/*

# Protect API endpoints
/api/internal/*

Exploit Blocking

Automatically block common attack patterns.

Rules are grouped by category and can be toggled per category or per rule.

Blocked Categories

CategoryExample Pattern
SQL InjectionUNION SELECT, ' OR '1'='1
XSS / Code Injection<script>, javascript:
Remote File Inclusion (RFI)http://, php:// and other remote includes
Path Traversal../, ..%2f
Scanner / Tool DetectionDetection of known scanners and attack tools
HTTP MethodBlock dangerous HTTP methods

If a specific URI produces false positives, you can add a URI-scoped exception per rule so the rule is bypassed only on that path.

Advanced Configuration Security

Blocking Dangerous Directives

Block security-risky directives in Nginx advanced configuration.

  • load_module - Loading external modules
  • lua_* - Executing Lua scripts
  • perl_* - Executing Perl scripts
  • js_* - Executing JavaScript
  • Shell commands within proxy_pass

Configuration Validation

  • Nginx configuration syntax check
  • Security vulnerability pattern detection
  • Dangerous configuration warnings

Config Rollback

Provides an automatic rollback mechanism to safely apply Nginx configuration changes.

How It Works

  1. Create Backup: Automatically back up the existing config file before making changes
  2. Generate New Config: Create a new Nginx config file with the changes
  3. Test Config: Check syntax and validity with nginx -t
  4. Conditional Apply: Run nginx -s reload only if the test passes
  5. Automatic Rollback: Immediately restore the backed-up config if the test fails

Rollback Targets

FileDescription
domain.confProxy host configuration file
host_.confWAF configuration file (ModSecurity)
banned_ips.confIP block list
default.confDefault server configuration

Safety Guarantees

  • Atomic Write: File writes with no intermediate state via temp file → fsync → rename
  • Global Mutex: All Nginx operations are serialized with a mutex to prevent concurrent changes
  • Fail-Safe: Never run an Nginx reload if nginx -t fails

Security Headers

Security Header Presets

Provides predefined security header presets according to the security level.

PresetSecurity LevelDescription
StrictHighestIncludes HSTS preload, restrictive CSP, X-Frame-Options DENY
ModerateBalancedHSTS includeSubdomains, SAMEORIGIN, appropriate CSP
RelaxedCompatibilityBasic security headers only, compatibility first

Strict Preset

  • HSTS: 1 year, includeSubDomains, preload enabled
  • X-Frame-Options: DENY
  • Content-Security-Policy: allow self source only
  • Permissions-Policy: disable camera, microphone, etc.

Moderate Preset

  • HSTS: 1 year, includeSubDomains, preload disabled
  • X-Frame-Options: SAMEORIGIN
  • Referrer-Policy: strict-origin-when-cross-origin

Relaxed Preset

  • HSTS: 1 day, includeSubDomains disabled
  • X-Frame-Options: SAMEORIGIN
  • Referrer-Policy: no-referrer-when-downgrade

Custom Headers

In addition to presets, you can customize individual headers.

HSTS (HTTP Strict Transport Security)

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Content Security

HeaderDescription
X-Content-Type-Optionsnosniff - Prevents MIME sniffing
X-Frame-OptionsDENY or SAMEORIGIN - Prevents clickjacking
X-XSS-Protection1; mode=block - XSS filter
Referrer-Policystrict-origin-when-cross-origin
Permissions-PolicyControls access to browser features

Content-Security-Policy

  • Restrict script sources
  • Restrict style sources
  • Restrict frame sources
  • Restrict form actions

TLS Security

Protocol Versions

  • Allow only TLS 1.2 and above
  • Disable SSL 2.0/3.0, TLS 1.0/1.1

Cipher Suites

  • Allow only strong encryption algorithms
  • Disable weak ciphers
  • Forward Secrecy support

OCSP Stapling

  • Optimizes certificate status checking
  • Protects client privacy