Nginx Directory Listing - Restrict by IP Address

Sathish Kumar satcse88 at gmail.com
Fri May 18 06:36:08 UTC 2018


Hi Prajith,

I had tried this option but autoindex is not allowed under if statement.

location / {
  root /downloads;
if ($allowed = 1)
{
     autoindex on;
}

}

Error:
"autoindex" directive is not allowed here in domain.conf



Thanks & Regards
Sathish.V


On Fri, May 18, 2018 at 2:16 PM PRAJITH <prajithpalakkuda at gmail.com> wrote:

> Hi Satish,
>
> There are "if" constructs in nginx, please check http://nginx.org/r/if.
> if you want to allow multiple IP addresses, it might be better idea to use
> map. eg:
>
> map $remote_addr $allowed {
>     default         0;
>     1.1.1.1         1;
>     2.2.2.2         1;
> }
>
> and then in in the download location block
>
>  if ($allowed = 1) {
>         autoindex on;
> }
>
> Thanks,
> Prajith
>
> On 18 May 2018 at 05:35, Sathish Kumar <satcse88 at gmail.com> wrote:
>
>> Hi Team,
>>
>> 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.
>>
>> Can somebody provide the correct nginx config for the same.
>>
>> location / {
>> root /downloads;
>> autoindex on;
>> allow 1.1.1.1;
>> deny all;
>> }
>>
>> If I use the above config, only on 1.1.1.1 IP address can directory list
>> from this server and can file download but from other IP addresses download
>> shows forbidden, due to IP address restriction
>>
>> Is there a way to overcome this issue, thanks.
>>
>> Thanks & Regards
>> Sathish.V
>>
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20180518/4ed5d343/attachment-0001.html>


More information about the nginx mailing list