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 2


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 at 12:49

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.