Authentication layer, help needed

i am migrating from SQUID to NGINX.

While using SQUID, we had a IP based authentication layer:

if request to http://siteurl/servicename/service.php → check list (data
is saved in a file as tupel of ip:username:password)
if requesting client ip eq list ip → rewrite url to backend as

What is the best method to implement this on NGINX? I am pretty new to
nginx, proxy function and ssl is working like a charm, but i dont know
what method i should use.
At the moment i am experimenting to use the SimplePerl Module to handle
my needs (i am also new to perl, but day to day there is a effort in
handliung it). Is this the right way? Anyone there with a better idea?

Thanks in advance for your help - and thanks to Igor for this great
piece of software!

Posted at Nginx Forum: