ipfence home page local-first intrusion prevention for Linux

Manual pages

Nginx, Caddy and proxies

Both web detectors are off until you enable them and say how clients reach you. Only you know whether a CDN or proxy sits in front.

Settings file (TOML)

[nginx]
enabled = true
clients = "direct"     # visitors connect to this machine themselves

What counts: exploit probes only

A 401 or 403 is not proof of a failed login, so neither is counted. These are:

Probe Matches Only when the response is 4xx
env-file a file named .env, .env.local, .env.production, .env.prod, .env.backup, .env.bak, .env.save, .env.old yes
git-metadata exactly /.git/config or /.git/HEAD yes
credential-file exactly /.aws/credentials, /.ssh/id_rsa, /.ssh/id_ed25519 yes
wp-config-backup wp-config.php backup names (.bak, .old, .save, .swp, .orig, ~) yes
path-traversal ../ together with etc/passwd or etc/shadow, after decoding no
phpunit-eval the PHPUnit eval-stdin.php path no
jndi-injection ${jndi: in the request target, user agent or referrer no

Requiring a 4xx for file probes means a site that really serves such a path is never penalized. The threshold is 3 probes in 10 minutes. If you run a security scanner against your own site, allowlist it.

Nginx formats

format Matches
"combined" (default) nginx's built-in format (Debian and Ubuntu packages)
"main" the format defined by nginx.org and RHEL-family packages, which adds "$http_x_forwarded_for"
"common" the common log format
your log_format text for example $remote_addr [$time_iso8601] "$request" $status

A custom format must contain $remote_addr (or $realip_remote_addr), $request, $status and $time_local or $time_iso8601; separate adjacent variables; not repeat one; and put the address before anything a client controls. It must use nginx's default escaping.

A line must match completely. If recent lines do not, the detector stays off and status says so, suggesting "main" when that fits. Nothing is switched automatically. Nginx error logs are not read.

Settings that disable the Nginx detector

ipfence reads /etc/nginx/nginx.conf and included files (at most 64 files):

  • realip (set_real_ip_from, real_ip_header) rewrites $remote_addr to a header-derived value. The detector is refused unless your format records $realip_remote_addr, the address that actually connected.
  • log_format … escape=none anywhere lets clients forge log lines. The detector is refused.

The check repeats every minute while the daemon runs. If either appears, the reader stops and lines written in the meantime are never processed. Lines logged in the minute before detection could already have been acted on. Configuration held outside /etc/nginx, or inside a container, is not checked.

Caddy

Access logging is opt-in in Caddy. Add a log directive with JSON output, then point ipfence at it:

Plain text

example.com {
    log {
        output file /var/log/caddy/access.log
        format json
    }
}

Settings file (TOML)

[caddy]
enabled = true
clients = "direct"
access_logs = ["/var/log/caddy/access.log"]   # or: journal_unit = "caddy.service"

Create the log directory if your package does not, owned by the caddy user. Only entries from the http.log.access logger with remote_ip, status and ts are read (Caddy 2.5 or later).

Proxies and forwarded addresses

The address your firewall sees is the peer that opened the connection. A forwarded header names someone else, and anyone can send one.

  • ipfence bans only peer addresses. Forwarded headers never choose the target.

  • With clients = "proxied" you list your proxies:

    Settings file (TOML)

    [proxy]
    trusted = ["10.0.0.2"]
    
    [nginx]
    enabled = true
    clients = "proxied"

    A probe from a trusted proxy is counted and listed under "Probes through a trusted proxy", with the reported visitor when the server logs one. Nothing is banned: blocking the visitor here would not stop them, and blocking the proxy would cut off everyone. Block such visitors at the proxy or CDN.

  • A probe from any other peer is a direct connection and is banned as usual, whatever headers it carries.

  • The reported visitor comes from Caddy's client_ip field. The Caddy versions tested here (2.6.x) do not log it, so the column was empty. With Nginx it appears only when your format has both $realip_remote_addr and $remote_addr.

If you say "direct" but a CDN is in front, ipfence will ban CDN addresses and block real visitors. If you are unsure, do not enable the detector.

Rotation

Rename-and-create rotation (logrotate's default) is followed: the old file is read to its end and the new one from its start. With copytruncate, lines written between the copy and the truncation are lost, and nothing can recover them. Rotated and compressed copies are not read.

A newly configured existing log is followed from its end; history is not replayed. Symlinked log paths are refused: configure the real path. Lines over 16 KiB (Nginx) or 64 KiB (Caddy) are dropped and counted.