Nginx Proxy Guard

Guides

Reading logs and block reasons

By the end of this page you can find in the logs why a request was blocked and go to the settings that control that cause. You also know what to check when logs stop appearing.

Before you start

  • Your role needs permission to read logs.
  • If a proxy such as Cloudflare sits in front of NPG, set up Settings → Trusted Proxies first, or the logs record the proxy's address instead of the visitor's. (Running behind Cloudflare)

The log tabs

Logs in the top menu has these tabs.

TabContents
Access LogsEvery HTTP request that went through the proxy. Blocked requests are here too, with a Block Reason.
WAF EventsRequests that matched WAF rules: rule ID, message, and whether they were blocked.
Bot FilterRequests the bot filter blocked, with the bot category
Exploit BlocksRequests the Block Exploits rules blocked, with the rule name
StreamSessions of TCP/UDP stream hosts: client IP, protocol, status, bytes sent, session time, backend
System LogsNPG's own activity
Admin AuditWho changed which setting, and when
Raw FilesRotation and retention of the raw log files nginx writes, and downloads
Access logs: a list mixing 200, 403 and 404 responses
Access logs: a list mixing 200, 403 and 404 responses

Block reasons

The Block Reason in Access Logs tells you which NPG feature blocked a request. The Block Reason filter groups requests by cause.

Block reasonFeature that blocked itWhere to change it
WAFModSecurity WAFWhen the WAF blocks legitimate requests
ExploitBlock ExploitsWAF / Blocking → Exploit Block Rules
Bot FilterBot filterThe host's Security tab, or WAF / Blocking → Global Bot Filter
Geo BlockGeoIP restrictionThe host's Security tab, or Global GeoIP
CloudCloud provider blockingThe host's Security tab, or Global Cloud Blocking
Banned IPManual bans, Fail2ban, WAF Auto-BanWAF / Blocking → IP Ban Management
URI BlockURI block rulesWAF / Blocking → URI Block Management
Access DeniedAccess listAccess Control → Access Lists
FilterFilter subscriptionsSettings → Filter Subscriptions
Rate LimitNPG's rate limitThe host's Protection tab, or Global Rate Limit

To exempt an address from these blocks, see Trusted IPs, exceptions and precedence.

Log details

Clicking a row opens Log Details.

  • The Block Reason section at the top adds detail for the cause: rule ID and attack type for the WAF, the rule name for Exploit, the bot category for the bot filter, the matched URI for URI blocks. For a filter subscription block it shows which subscription and which entry matched, and lists separately any disabled subscription that holds the same entry.
  • Client Info has the IP, the GeoIP location (country, city, ASN, organization), the User Agent and the Referer.
  • Request Time and Upstream Server are shown, plus the Retry path if there were retries.
  • Raw Log shows the line nginx wrote, as written.
  • From this screen you can ban the IP, block the URI or exclude a WAF rule directly.
Access log details: block reason, client info, request details
Access log details: block reason, client info, request details

Log collection rules

Requests that are frequent but not worth keeping, such as WebDAV sync PROPFINDs or health checks, can be left out of storage.

  1. Click the Collection rules button in the Logs → Access Logs toolbar.
  2. Find the host, click Edit, and fill in Status codes (for example 207, 3xx), Methods (for example PROPFIND, OPTIONS) and Paths starting with (one per line). To leave out all of a host's logs, turn on Don't store this host's access logs. Stream hosts have Don't store this host's sessions.
  3. Click Save.
Log collection rules: an HTTP host with rules and a stream host
Log collection rules: an HTTP host with rules and a stream host

Requests that match a rule are not stored, so they are missing from the logs and statistics. Requests NPG blocks and WAF events are always stored regardless of the rules, and Fail2ban still counts every request. Path rules do not apply while Strip query string from access log under Settings → Global Settings → Advanced is on.

Raw log files

Logs → Raw Files sets rotation and retention for the raw files nginx writes (/etc/nginx/logs/access_raw.log, and stream_raw.log for streams), and lets you preview or download them.

  • Max File Size (MB): checked every hour; a file larger than this is rotated. Files are also rotated every day at midnight regardless of size.
  • Retention Period (days): rotated files older than this are deleted at the next rotation.
  • Compress Rotated Files: compresses with gzip to save disk space.
Raw log files: rotation settings and file list
Raw log files: rotation settings and file list

How long logs are kept in the database is set with Retention Period (days) in Log Settings on the log screen.

Check that it works

  • Open a proxy host in a browser, then check that the request appears in Access Logs. Collection lags by a few seconds.
  • To try a block, run WAF / Blocking → WAF Tester against a host with the WAF on and check that WAF Events records it.

When no logs appear

  • Check the search conditions. Look for a date range, host or Exclude Filters (NOT) that hides the rows. Excluding status code 403 also hides requests the WAF blocked.
  • Check the collection rules. A host set to store nothing, or a path rule, keeps its requests out of storage.
  • See whether the raw file grows. If access_raw.log grows under Raw Files but nothing appears on screen, the problem is in the API's collection step. Look for LogCollector errors in docker logs npg-api.
  • HTTPS requests leave no record at all. An HTTPS connection whose domain (SNI) matches no proxy host is refused during the TLS handshake, so no HTTP log line is written. Check that the domain is registered on a proxy host.
  • Only WAF Events is empty. Many hostile requests are stopped earlier at the nginx level by country blocking, the bot filter, banned IPs or Block Exploits. Look at the Block Reason in Access Logs as well. Whether the host's WAF is on can be checked with WAF Tester.

Things that are easy to misread

  • A 429 whose block reason is not Rate Limit. NPG's rate limit blocks before the request reaches the backend, so Upstream Server is empty. A 429 with Upstream Server filled in was returned by the backend itself.
  • A WebSocket request with a very long request time. For a row with status 101, Request Time is how long the connection stayed open. It does not mean the response was slow.
  • Every client IP is the same private or CDN address. Settings → Trusted Proxies is not set up, or Real IP header does not match the header the proxy in front sends.