1

first i have this in my nginx.conf

server {
    listen 80;

    root /home/user/files;
    index index.php index.html index.htm;

    server_name mydomain.com;

    location / {
        autoindex on;
       }

    #this option will allow auto index on video directory
     location ~ ^/video {
                auth_basic            "Restricted";
                auth_basic_user_file  /etc/nginx/.htpasswd;
                include /etc/nginx/conf.d/php;
                autoindex on;
                autoindex_exact_size on;
}
    #only spesific ip allow to download files in video directory
    location ~ ^/video/* {
               autoindex off;
               allow myip;
               deny all;
       }

}

it seems allow rules is not working, i still got 403 when i try to download the video files.

is there something wrong with my conf ?

  • Please change ^/video/* to ^/video/.*! Note the plus dot character before asterisk! – uzsolt Jul 18 '15 at 13:30
  • no , its still not working , now i can download the files, with or without allow ip on conf file – juicebyah Jul 18 '15 at 14:01
  • Replace the order of two (regexp) locations! – uzsolt Jul 18 '15 at 15:15
  • nothing change still downloadable – juicebyah Jul 18 '15 at 16:25
1

Put them in the same location block.

location /video/ {
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/.htpasswd;
    allow myip;
    deny all;
    include /etc/nginx/conf.d/php;
    autoindex on;
    autoindex_exact_size on;
}

I can't see why you are using regexp match (location ~ regexp) for the path where simple forward match would suffice, and mixing autoindex on/off for the same location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.