How to check IP range in nginx location?

You can achieve that (for example) using ranges and the nginx geo module.

This is the example from the page:

Example with ranges:

geo $country {
    ranges;
    default                   ZZ;
    127.0.0.0-127.0.0.0       US;
    127.0.0.1-127.0.0.1       RU;
    127.0.0.1-127.0.0.255     US;
    10.1.0.0-10.1.255.255     RU;
    192.168.1.0-192.168.1.255 UK;
}

Alternatively you can calculate the CIDR notation of your range using any calculator (or mentally, if you're so inclined) and block them using the nginx http access module.

For your example this would look something like this:

location /whatever {
    deny  123.132.123.15/32
    deny  123.132.123.16/28
    deny  123.132.123.32/28
    deny  123.132.123.48/31
    deny  123.132.123.50/32;
    allow all;
}