Nginx Directory Listing - Restrict by IP Address

Francis Daly francis at daoine.org
Fri May 18 16:35:51 UTC 2018


On Fri, May 18, 2018 at 08:05:34AM +0800, Sathish Kumar wrote:

Hi there,

> We have a requirement to allow directory listing from few servers and
> disallow from other ip addresses and all IP addresses should be able to
> download all files inside the directory.

"Directory listings" is presumably only relevant when the request url
ends in /.

So if you have "autoindex on", then all you need to do is disallow some
IP addresses from accessing those urls.

> location / {
> root /downloads;
> autoindex on;
> allow 1.1.1.1;
> deny all;
> }

Replace the allow/deny part with

    location ~ /$ {
        allow 1.1.1.1;
        deny all;
    }

and it should do what you want.

The end result is: request ends in / --> check the allow list; otherwise,
allow as normal.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list