Quantcast
Channel: Nginx Forum
Viewing all articles
Browse latest Browse all 53287

Differentiate locations based on request method

$
0
0
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

Viewing all articles
Browse latest Browse all 53287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>