A static site or a read-only API has no reason to accept POST or DELETE. Requests like that are usually scanners. limit_except refuses them before they reach anything.
location /api/public/ {
limit_except GET {
deny all;
}
proxy_pass http://127.0.0.1:8081;
}
The methods after limit_except are the ones that stay allowed, and the block applies to everything else. GET automatically includes HEAD. A POST then gets a 403 and a GET goes through as normal.
Inside the block you can use more than deny all. allow 203.0.113.10; deny all; lets one address still write, and auth_basic asks for a login only for write methods while reading stays open.
The syntax is easy to read backwards: you list what you allow, not what you block. It also returns 403, not the 405 Method Not Allowed that the HTTP spec suggests, so a client sees “forbidden” rather than a hint about the method. If that matters to you, an if ($request_method !~ ^(GET|HEAD)$) { return 405; } in the location does it. Remember CORS preflight too: a browser on another domain sends OPTIONS first, so I’d add it to the list if such pages call your API.
Further reading: limit_except
Going deeper: ๐ Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)