5.7 KiB
Behind a reverse proxy
Flypaper is meant to sit behind the reverse proxy that already owns ports 80/443. The proxy
forwards to the trap port 8080; the dashboard port 8081 is never forwarded. Two rules
apply to every proxy:
-
Set
X-Real-IP(andX-Forwarded-For) to the client address. -
Flypaper must trust the proxy. By default it trusts every private network (
10/8,172.16/12,192.168/16, loopback,fc00::/7), which covers a proxy in a Docker network or on the LAN. Headers from public addresses are ignored, so bots can't fake their address. To narrow it down, setFlypaper__Http__TrustedProxies__0to the proxy's IP or subnet, e.g. the Docker network's subnet:docker network inspect <network> -f '{{(index .IPAM.Config 0).Subnet}}'
Also turn off response buffering for Flypaper, otherwise the proxy collects the drip and the
bot never sees it. Flypaper sends X-Accel-Buffering: no, which nginx honors.
What to send to Flypaper
- The catch-all server. Requests for hosts you don't serve (mostly the bare IP) go to Flypaper. This is where almost all scanners end up.
- Optionally, trap paths on your real domains. Forward only the bait paths, e.g.
/.envor/wp-login.php, from your real sites to Flypaper. Every request on the trap port is caught, so nothing else is needed.
Known hosts (optional) change this for hosts you list: on the trap port, a known host is
caught only on the configured trap paths, and its other paths get a plain 404 without being
logged. That is useful if your proxy forwards more than the bait paths of a real domain, for
example a whole location. Unknown hosts are always caught. The dashboard is never reachable
on the trap port.
An HTTPS catch-all is rarely worth it. Scanners of unknown hosts mostly speak plain HTTP to
the bare IP, and an HTTPS catch-all would need a certificate for names you don't own. Let the
proxy reject unknown TLS handshakes instead (nginx: ssl_reject_handshake on;).
Nginx Proxy Manager
Put Flypaper into the same Docker network as NPM (the examples use the container name
flypaper).
-
Settings → Default Site → Congratulations Page. With this setting NPM writes no default server of its own. Any other choice (404, redirect, HTML) creates one, and nginx refuses to start with two default servers.
-
Create
/data/nginx/custom/http.confin the NPM container (on the host: inside NPM's data volume):# Catch-all: every HTTP request whose Host matches no proxy host goes to Flypaper. server { listen 80 default_server; # the HTTP port NPM listens on inside its container listen [::]:80 default_server; server_name _; location / { # A variable makes nginx resolve the name per request, so NPM still starts # (and serves your sites) while the Flypaper container is down. resolver 127.0.0.11 valid=30s; set $flypaper http://flypaper:8080; proxy_pass $flypaper; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; proxy_read_timeout 1h; } } -
Test and reload:
docker exec <npm-container> nginx -t, thendocker exec <npm-container> nginx -s reload. -
Optional trap paths on a real domain: in the proxy host's Advanced tab add
location ~* ^/(\.env|\.git/|wp-login\.php|xmlrpc\.php) { resolver 127.0.0.11 valid=30s; set $flypaper http://flypaper:8080; proxy_pass $flypaper; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; }
To undo the catch-all, delete custom/http.conf and reload.
Plain nginx
Remove any existing default_server (on Debian/Ubuntu often sites-enabled/default) and add
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:8080; # or a variable + resolver for a Docker name, see NPM
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_read_timeout 1h;
}
}
With Flypaper on the same host, nothing else is needed: loopback is trusted by default.
Caddy
# Catch-all for every host on port 80 without its own site block
:80 {
reverse_proxy flypaper:8080 {
header_up X-Real-IP {remote_host}
flush_interval -1
}
}
# Optional trap paths on a real site
example.com {
@trap path /.env /.git/* /wp-login.php /xmlrpc.php
reverse_proxy @trap flypaper:8080 {
header_up X-Real-IP {remote_host}
flush_interval -1
}
reverse_proxy your-app:8080
}
Traefik
Traefik sets X-Real-Ip and X-Forwarded-For by default. Labels on the Flypaper container
(Traefik v3):
labels:
traefik.enable: "true"
# Lowest priority: matches only hosts no other router claims
traefik.http.routers.flypaper-catchall.rule: "HostRegexp(`.+`)"
traefik.http.routers.flypaper-catchall.entrypoints: web
traefik.http.routers.flypaper-catchall.priority: "1"
# Optional trap paths on a real site
traefik.http.routers.flypaper-bait.rule: "Host(`example.com`) && (Path(`/.env`) || PathPrefix(`/.git/`) || Path(`/wp-login.php`))"
traefik.http.routers.flypaper-bait.priority: "1000"
traefik.http.services.flypaper.loadbalancer.server.port: "8080"