Home > Article > Operation and Maintenance > How to configure Nginx to list directories and files and control access permissions with passwords
Use nginx to list directories
Preparation - install nginx and create some directories and files:
Copy the code The code is as follows:
$ sudo apt-get install nginx
$ cd /usr/share/nginx
$ mkdir web
$ sudo mkdir directory{1,2,3}
$ sudo touch file {1,2,3}
$ ls
directory1 directory2 directory3 file1 file2 file3
##nginx configuration:
listen 80;
server_name 192.168.1.201;
index index.html;
autoindex_exact_size off;
autoindex_localtime on;
}
When accessing http://192.168.1.201, the screen displays:
Authorize access to specified directories
Some directories do not want everyone to see them. They can only be accessed by designated users after entering their passwords. For example, directory can only be accessed by test1:#step1Install htpasswd
$ sudo apt-get install apache2-utils
step2 Create a password file
$ sudo htpasswd -c /home/test/. htpasswd test1
new password:
re-type new password:
adding password for user test1
step3Modify nginx configuration file
$ sudo vim /etc/nginx/conf.d/list.conf
listen 80;
server_name 192.168.1.201;
index index.html;
autoindex_exact_size off;
autoindex_localtime on;
auth_basic "input you user name and password";
auth_basic_user_file /home/test/.htpasswd;
}
}
The above is the detailed content of How to configure Nginx to list directories and files and control access permissions with passwords. For more information, please follow other related articles on the PHP Chinese website!