一、先创建密码文件
1.安装httpd-tools
|
1 |
yum -y install httpd-tools |
2.创建密码文件
|
1 |
htpasswd -c /etc/nginx/conf.d/password dingqiao |
二、修改nginx配置文件
|
1 2 3 4 5 6 7 8 9 10 11 |
location /work/ { auth_basic "请输入用户和密码"; auth_basic_user_file /etc/nginx/conf.d/password; sendfile on; # 开启高效文件传输模式(零拷贝) autoindex on; # 开启目录文件列表 autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes autoindex_localtime on; # 显示的文件时间为文件的服务器时间 charset utf-8,gbk; # 避免中文乱码 } |
参考资料:
https://blog.csdn.net/Michelle_Zhong/article/details/125506461