You are not logged in.
Hi everyone
I'm trying out Nginx in place of apache. In apache, I have special folder and sub folder that I want to enable Directory Listing with basic authentication. I have it done with
autoindex on; auth_basic; auth_basic_user_file
. However, I also store files in that directory that I would like direct access without any authentication. In apache I get that done with a <Filematch> directive. to match any file, then allow from all to override the authentication. I haven't been able to find any similar configuration for nginx. Any thought on this would be much appreciated.
Last edited by pntruongan (2018-12-20 02:21:44)
Offline
Just add another location block specifying the files or a pattern that matches the files to specify settings for them.
https://www.digitalocean.com/community/ … ion-blocks
Last edited by Trilby (2018-12-09 17:01:13)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Just add another location block specifying the files or a pattern that matches the files to specify settings for them.
Well, there's a lot of files in that folder and its sub folder, so much that it's almost impossible to specify a pattern. Is there some kind of pattern to match files but not sub folder?
Offline
Is there some kind of pattern to match files but not sub folder?
Yes. Just write a regular expression excluding (additional) /'s.
Or just invert the logic, and apply the settings in your first post just to the specific directories you want them applied to rather than to everything under them.
Last edited by Trilby (2018-12-09 17:03:05)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
pntruongan wrote:Is there some kind of pattern to match files but not sub folder?
Yes. Just write a regular expression excluding (additional) /'s.
Or just invert the logic, and apply the settings in your first post just to the specific directories you want them applied to rather than to everything under them.
Inverting the logic seem good. It was easier to write a pattern ending with forward slash / and protect that location with basic authentication. I will try it out. Thank you very much.
Offline
OK, so this is h
location ~ ^/directory_name(.*/)$ { #This is to catch any path start with directory name and end with a slash /
alias /path/to/that/directory_name$1; # alias to serve the exact folder
auth_basic "ABC";
auth_basic_user_file /path/to/password/file/.htpasswd;
autoindex on;
}
outside this location block I have another block setup to serve all file with no password but without no autoindex. That seem to cut it, I leave it here for anyone happens to need it
Offline