Return a JSON error
Custom JSON body for 429 and other error responses
error_page 429 /429.json;
location = /429.json {
default_type application/json;
return 429 '{"error":"rate_limited"}';
}
More nginx commands
-
server { listen 80; return 301 https://$host$request_uri; }Send all HTTP traffic to HTTPS with a permanent 301 redirect
-
curl -s http://localhost/stub_statusBuilt-in status page with active, reading, writing and waiting connections; needs a stub_status location
-
deny 192.168.1.0/24; deny 10.0.0.1; allow all;Block a subnet and a single IP inside a server or location block
-
location /ws/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; }WebSocket proxy with the required Upgrade and Connection headers
-
nginx -tCheck the nginx config syntax without reloading