Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm able to use limit_req to rate-limit all requests to my server.

However I'd like to remove the rate restriction for certain IP addresses (i.e. whitelist) and use a different rate restriction for certain others (i.e. certain IPs I'd like as low as 1r/s).

I tried using conditionals (e.g. if ( $remote_addr = "" ) {}) but that seems to work only with rewrite rules, not for rate-limit rules.

share|improve this question
add comment

1 Answer

You can safely use named locations, such as "@location" in an if() block.

See: http://wiki.nginx.org/IfIsEvil

Something like this should work:

http {

   limit_req_zone $binary_remote_addr zone=delay:10m rate=1r/m;

   server {

      error_page 410 = @slowdown;

      if( $remote_addr != "" ) {
         return 410;

      location @slowdown {
         limit_req zone=delay burst 5;

      location / {

Fill in "location @slowdown { }" with the same information as "location / { }, such as proxy_pass if you're using nginx as a reverse proxy.

share|improve this answer
I'm not sure I understand the 410 part? Do the client actually see a http 410 status code? –  svrist Feb 27 '12 at 14:35
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.