Given the following NGinx config, how would I alter it to issue a Retry-After header to ONLY 429 reponses?
limit_req_zone $binary_remote_addr zone=ip:10m rate=5r/s;
limit_req_status 429;
limit_conn_status 429;
server {
listen 80;
location /api {
limit_req zone=ip burst=12 nodelay;
proxy_pass http://website;
}
}
There is variable
$status
that holds response status value. You could usemap
directive to define another variable that holds retry delay and useadd_header
directive.add_header
will not send header if value (second argument) is empty. And we needalways
flag, otherwise it will not set header for 429 status code.Full example: