Nginx Proxy Guard

Features

Automatic bans

When one IP keeps producing failed responses or WAF events within a short time, NPG bans it automatically. Banned IPs are listed, and can be released, in one place. This page covers the automatic ban mechanisms together with URI blocks, which close off paths, and the exploit block rules, which stop known attack patterns.

At a glance

MechanismWhat it counts or blocksBan scopeScreen
Per-host Fail2banFailed responses a host returns (401 and 403 by default)that hostWAF / Blocking → Fail2ban
Global Fail2banFailed responses to requests that matched no host (direct-IP access, unknown hostnames; 400 and 444 by default)every hostWAF / Blocking → Global Fail2ban
WAF auto-banRule events of blocking-mode WAFsevery hostSettings → WAF Auto-Ban
Manual bansIPs you addthe chosen host, or every hostWAF / Blocking → IP Ban Management
URI blocksRequests to the paths you listthe host with the rule, or every hostWAF / Blocking → URI Block Management
Exploit block rulesPatterns such as SQL injection, XSS, path traversal and scannershosts with Block Exploits onWAF / Blocking → Exploit Block Rules

Addresses that are never banned

These addresses are never banned automatically:

  • loopback addresses (127.0.0.1 and the like)
  • addresses in Settings → Trusted Proxies, because banning a proxy would ban every visitor behind it
  • the Global Trusted IPs under Settings → WAF Auto-Ban. They are left out of Fail2ban and WAF auto-ban, and bans already in place are dropped from the nginx configuration.

With Never ban local network addresses on in the global Fail2ban, Fail2ban also does not ban private ranges (10.x, 172.16–31.x, 192.168.x, fc00::/7) and link-local addresses (they are still counted). The setting applies to the per-host Fail2ban as well, but not to WAF auto-ban.

Settings → WAF Auto-Ban: auto-ban settings, Global Trusted IPs, WAF bypass option
Settings → WAF Auto-Ban: auto-ban settings, Global Trusted IPs, WAF bypass option

If you run behind a proxy such as Cloudflare, set Settings → Trusted Proxies first. Without it every request appears to come from the proxy. See Running behind Cloudflare.

Per-host Fail2ban

Turning on Fail2ban (Auto IP Ban) under the proxy host's edit dialog → Security tab saves at once (it is shown on saved hosts only). Change the details under WAF / Blocking → Fail2ban by clicking Configure on the host.

FieldMeaningDefault
Max RetriesFailures allowed before a ban5
Find Time (sec)The window in which failures are counted600
Ban DurationHow long the ban lasts. 0 seconds is a permanent ban.3600 seconds
Fail CodesHTTP status codes counted as failures, comma-separated401,403
ActionBlock IP, Log Only (no ban, written to the API log), Notify Only (no ban, sends a notification)Block IP

The per-host Fail2ban counts only responses the host itself returns. Responses that belong to no host, such as the 444 sent to direct-IP requests, cannot be counted there; that traffic is handled by the global Fail2ban.

Global Fail2ban

WAF / Blocking → Global Fail2ban counts requests that arrive by IP address or with a hostname you have not configured. Its bans apply to every host at once, so a false positive affects all your sites.

Global Fail2ban settings
Global Fail2ban settings
FieldDefault
Enable global fail2banoff
Max Retries5
Find Time (sec)600
Ban Duration3600 seconds
Fail Codes400,444
ActionLog Only
Never ban local network addressesoff
  • Set Settings → Trusted Proxies before turning it on. While Trusted Proxies is empty, the global Fail2ban does nothing.
  • Start with Log Only for a few days, then switch to Block IP.
  • Not counted: domains configured as redirect hosts, requests too malformed for the hostname to be read, NPG's own self-checks, and loopback and trusted-proxy addresses.
  • 403 and 404 come only from hosts you configured, so adding them to the fail codes here catches nothing extra.

WAF auto-ban

Turn it on under Settings → WAF Auto-Ban. When one IP's WAF events reach the threshold within the window, that IP is banned on every host.

FieldMeaningDefault
WAF Auto IP BanTurns the feature onoff
Ban Threshold (WAF Events)Ban after this many events10
Detection Window (Seconds)The window in which events are counted300
Ban Duration (Seconds)How long the ban lasts. 0 is permanent.3600
  • Only events from hosts in blocking mode are counted. Detection mode logs and never bans.
  • Events of disabled WAF rules (rule exclusions) and events from global trusted IPs are not counted.
  • If legitimate requests trip the WAF and end in bans, narrow down and disable the rule responsible as described in When the WAF blocks legitimate requests.

On the same screen, Global Trusted IPs takes one IP or CIDR per line (lines starting with # are comments); domains go in the domain field below. With Trusted IPs also bypass the WAF (ModSecurity) on, their requests also skip WAF inspection (off by default). What the global trusted IPs exempt from is listed in Trusted IPs, exceptions and precedence.

IP Ban Management

WAF / Blocking → IP Ban Management lists the IPs banned by Fail2ban, WAF auto-ban and by hand.

Banned IP list
Banned IP list
TabContents
Global BansBans that apply to every host
Per-Host BansBans that apply to one host; can be filtered by host
Ban HistoryBan and unban records (with sources such as manual, expired or WAF auto-ban) and frequently banned IPs
  • Filter by ban type (auto, manual, WAF, Fail2ban) and see the time remaining and the expiry. With GeoIP on, each address shows its country.
  • Add IP Ban bans an address by hand: choose Apply to Host (one host or Global Ban (All Hosts)), the duration (5 minutes, 10 minutes, 30 minutes, 1 hour, 24 hours, 7 days, 30 days, Permanent Ban) and a reason.
  • Change duration on a ban sets a new duration counted from now, or makes it permanent.
  • Unban, unban selected, and unban all in the current filter are available. Unbanning all cannot be undone.
  • Opening an address shows its activity: recent requests, blocked requests, times banned, and the hosts and paths it targeted most.

A banned IP gets a 403 and is logged with the block reason Banned IP. If you have set up a notification channel, Fail2ban and WAF auto-ban bans can send the "IP banned" notification, grouped every five minutes (Notifications).

URI blocks

WAF / Blocking → URI Block Management blocks requests by path. Use it to cut off requests for paths you do not serve, such as /wp-admin or /.env, before they reach the backend.

URI block rules
URI block rules
TabContents
Global RulesRules that apply to every proxy host, checked before the per-host rules
Per-Host RulesAdd Host picks a host and holds its rules; Enable URI Blocking turns them on or off per host
HistoryRecords of rules added and removed, and of hosts enabled and disabled
FieldMeaning
URI PatternThe path to block, for example /wp-admin, /xmlrpc.php, \.php$
Match TypeExact, Prefix (every path that starts with the pattern), Regex
DescriptionA note (optional)
Quick TemplatesBlock WP Admin, Block XML-RPC, Block WP Login, Block PHP, Block .env
Exception IPsIPs that bypass every rule of this host (or of the global rules)
Allow Private IPsPrivate ranges (10.x, 172.16–31.x, 192.168.x) bypass the blocks.
Allowed IPs for this ruleIPs or CIDR ranges that only this rule lets through (+ Allowed IPs on each rule), for example to open the login path to the office IP only

Exception IPs can also take domains (DDNS names). A blocked request gets a 403 and is logged with the block reason URI Block. Access lists and global trusted IPs are not exceptions to URI blocks; put the addresses to let through in the exception IPs.

Exploit block rules

Block Exploits on a proxy host's Security tab blocks known attack patterns in nginx. New hosts start with it on. The rules are managed under WAF / Blocking → Exploit Block Rules.

Exploit block rule list
Exploit block rule list
TabContents
Global RulesThe rules by category; disable a rule on every host or edit its pattern.
Per-Host RulesDisable or enable rules for each host that has exploit blocking on.
RFI ExceptionsPatterns that skip exploit blocking, such as for remote file inclusion (RFI). Global and per-host exceptions are merged.

The categories are SQL Injection, XSS / Code Injection, Remote File Inclusion, Path Traversal, Scanner / Tool Detection, HTTP Method and Custom Rules. Each rule shows where its pattern applies (Query String, Request URI, User Agent, Request Method), and the pattern editor can test the pattern against sample input.

A blocked request gets a 403 and appears under Logs → Exploit Blocks with the rule name. Exploit blocking is separate from the WAF, so WAF rule exclusions and the "Trusted IPs also bypass the WAF" option do not affect it.

Limits

  • TCP/UDP stream sessions are not counted by Fail2ban or WAF auto-ban.
  • Redirect hosts cannot use URI blocks; their only exploit protection is the redirect host's Block Exploits option.
  • Fail2ban counters are kept in Valkey when it is available, otherwise in the API process's memory. Counters kept in memory are lost when the API restarts.