Welcome! Log In Create A New Profile

Advanced

Differentiate locations based on request method

Posted by donuk 
Differentiate locations based on request method
February 27, 2013 07:03AM
Hi,

I'm relatively new to nginx and hoping I've just missed something obvious but have had no luck googling for answers, so here goes.

Is there a way to set up several location blocks (or server blocks) based on request method? I've hit several situations where this would be useful and not sure how best to either achieve it or work around it.

Currently I'm trying to rate-limit post requests to a particular page on my site. I'd like to do something like the following:

limit_req_zone $binary_remote_addr zone=default:10m rate=1r/s;
limit_req_zone $binary_remote_addr zone=contact:10m rate=2r/m;
server {
location /contact-us/ {
limit_req zone=default burst=5;
}
if ($request_method = 'POST') {
location /contact-us/ {
limit_req zone=contact burst=5;
}
}
}

But you can't have a location (or a limit_req) inside an if statement.

The other situation I had trouble with was trying to set up separate proxies based on the request method, I don't know if there's a common fix for both these?

Thanks,
Don
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 312
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready