Restricting directory access to ip range


I’ve got the latest version of EasyEngine installed on Ubuntu 16.04. I’m attempting to restrict access of certain directories to specified IP ranges. For example, let’s say my domain is Then I would like to restrict access to the directory to the ip range and restrict to, etc.

I created a file called ip-filter.conf in the /var/www/ directory and put in some location blocks to restrict access, but it didn’t work. Evidently these location blocks are getting overridden.

My ip-filter.conf location blocks look like this:

location /dir1 { allow; deny all; }

How would I accomplish what I’m trying to do? Or is what I’m trying to do not really suited for nginx and rather I should use a WAF?

Thanks for the help.