nginx directory listing and directory access permission settings
滿天的星座
滿天的星座 2017-05-16 17:21:50
0
1
655

When reading the ThinkPHP document, I saw the following text: In order to prevent some servers from turning on directory browsing permissions and being able to directly enter the URL address in the browser to view the directory, the system has enabled the directory security file mechanism by default and will automatically When generating the directory, a blank index.html file is generated. Of course, the name of the security file can be set. For example, if you want to define the security file as default.html, you can add it in the entry file.

I hate redundant index.html, so I want to turn off the directory browsing permission directly. So the question is, how to turn off and turn on this permission in nginx?

滿天的星座
滿天的星座

reply all(1)
洪涛

The following is the answer I found on Baidu:

1. Directory listing

nginx only requires one command to display the files in the directory in the form of a list

autoindex on;

autoindex can be placed in location and will only work on the directory of the current location. You can also put it in the server directive block and it will apply to the entire site. Or put it in the http command block, it will take effect on all sites.

Here is a simple example:

server {
        listen   80;
        server_name  domain.com www.domain.com;
        access_log  /var/...........................;
        root   /path/to/root;
        location / {
                index  index.php index.html index.htm;
        }
        location /somedir {
               autoindex on;
        }
}

2.nginx prohibits access to a certain directory

Similar to Apache’s Deny from all, nginx has the deny all instruction to implement it.

To disable access to the dirdeny directory and return 403 Forbidden, you can use the following configuration:

location /dirdeny {
      deny all;
      return 403;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template