How to allow specific IP’s to a URL (not directory!) in Nginx

listed in answer

How to allow specific IP’s to a URL (not directory!) in Nginx
0 votes, 0.00 avg. rating (0% score)

ANSWER:

I managed to solve it myself, and this is how:

    set $deny_access off;

    if ($remote_addr !~ (123.123.123)) 
            set $deny_access on;
    
    if ($uri ~ "^/(specificurl)$" ) 
            set $deny_access on$deny_access;
    
    if ($deny_access = onon) 
            return 444;
    

by Lars from http://serverfault.com/questions/384092