I have 2 txt files that I placed at /home/forge/laravel58/public/files;
I want to index those 2 txt files when I goto my site/files
I've tried
location /files {
#auth_basic "Restricted";
#auth_basic_user_file /home/forge/laravel58/.htpasswd;
alias /home/forge/laravel58/public/files;
autoindex on;
}
Go to : site/files
, and see
403 Forbidden Nginx
Definition of Nginx Autoindex. Nginx autoindex is used the ngx http autoindex module to process the requests which was ending with the “/” slash character and it will produce the listing directory. Basically, the request is passed by using the ngx http autoindex module when the specified module will not find the index.
The trailing slash is essential for autoindex
to work, it should be:
location /files/ {
alias /home/forge/laravel58/public/files/;
autoindex on;
}
Next, check that nginx has execute permissions (+x
) on every folder in the path.
After that remove any index file from this folder, by default it's index.html
.
And finally, check that your location /
directive has attempt to try directories:
location / {
...
try_files $uri $uri/ ...;
^^^^^
}
The other answer about trailing slash being "essential for autoindex
to work" is 100% incorrect: trailing slash is not required here, although, it is, in actuality, the preferred paradigm, because otherwise you make it possible to access both regular files and directories like /filesSECRET
, one level up from /files/
, opening yourself to potential security issues.
In your situation, where /files
is the suffix of both the location
, as well as alias
, it is preferred to use root
instead of alias
. See http://nginx.org/r/alias and http://nginx.org/r/root.
In order for http://nginx.org/r/autoindex to work, the UNIX user under which the nginx process is running must have "read" permission on the final directory of the path, as well as "execute" permissions for every part of the path.
You can use stat(1)
, or ls -l
, to examine permissions, and chmod(1) to change the permissions. You'd probably want o+rx
on /home/forge/laravel58/public/files
, as well as o+x
on every single directory that's leading to the above one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With