How can I restrict access from external IP's for a ngnix location

Solution 1:

You should use nginx geo module for IP address maps. Your configuration would be like this with it:

geo $internal {
    default        0;
    127.0.0.0/8    1;
    10.0.0.0/8     1;
    172.16.0.0/20  1;
    192.168.0.0/24 1;
}

location /app/sniper {
    if ($internal != 1) {
        return 403;
    }
}