brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx limit_req slows brute-force attempts on a login page

Nginx
~/tips/tip-nginx-limit-req-login

location = /login { limit_req zone=login burst=5 nodelay;

Limits how often one client address may request a path and returns 429 beyond that.

A rate limit on one location is a cheap shield for a login form.

limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;   # http block
location = /login { limit_req zone=login burst=5 nodelay;
                    limit_req_status 429; }

The zone tracks clients by address, and rate=5r/m allows one request every 12 seconds. burst=5 lets a few extra requests through before nginx starts refusing, and nodelay serves them immediately. Rejected requests get 503 by default, and limit_req_status 429 returns the more accurate Too Many Requests. Behind another proxy every client looks like the proxy address unless the real client IP is restored first. State lives in shared memory, so the limit holds across all worker processes.

Further reading: ngx_http_limit_req_module

Going deeper: ๐Ÿ›œ Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link