Skip to content

Instantly share code, notes, and snippets.

@khairulcs
Created December 20, 2019 02:34
Show Gist options
  • Save khairulcs/cf1cdcc8869822483630f28fac1b5e8f to your computer and use it in GitHub Desktop.
Save khairulcs/cf1cdcc8869822483630f28fac1b5e8f to your computer and use it in GitHub Desktop.

Set the mapping before server block

 # whitelisted user agents - will not have limits applied
    map $http_user_agent $whitelist {
        ~*Macintosh 1;
        ~*iPhone 0;
    }

    # if whitelist is 0, put the binary IP address in $limit so the rate limiting has something to use
    map $whitelist $limit {
        0 $binary_remote_addr;
        1 "";
    }
    limit_req_zone $limit zone=perip:10m rate=1r/s;

put the limit in the location

location = / {
        limit_req zone=perip burst=1 nodelay;
        limit_req_status 444;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment