please, help me configure nginx so that it will hide files and directories from directory listing. Setting "Autoindex off" is not an option because nginx starts showing 403 error message. What I need is sort of a blank page with a directory name. Thank you.
2 Answers
Add an empty page named "index.html" into each directory, you'd like to hide and that's it. This works on Nginx, Apache and what ever.
-
Or index.php, or index.any_extension, depending on what's set for
index
directive. This is the method used by WordPress on some important directories! Just adding what's already mentioned by @Jens. Oct 7, 2013 at 4:25
Directory listing is disabled by default on the nginx
. To control indexing, one can use autoindex
parameter together with location
:
server {
listen 80;
server_name domain.com www.domain.com;
root /path/to/root;
location / {
index index.php index.html index.htm;
}
location /somedir {
autoindex on;
}
}
In the example above directory listing is enabled only in the /somedir
.
-
Yes removing autoindex or setting autoindex to off will disable directory listing and return forbidden if any directory is visited Jan 8, 2022 at 12:49