红联Linux门户
Linux帮助

Nginx访问目录身份验证

发布时间:2014-11-26 09:38:49来源:linux网站作者:sunbiao0526

假设/www/htdocs/ 为服务器根目录,新建test目录,当访问test目录时需要身份验证。


1. # cd /etc/nginx/conf/htpassword

2. /usr/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/test auth_user

3. # vi /etc/nginx/nginx.conf

server{

***
#test
location /test {
auth_basic "Restricted";
auth_basic_user_file  /usr/local/nginx/conf/htpasswd/test;
}

****
}


现在如果继续访问test/目录下的内容,就需要身份验证,输入 auth_user 和 密码就可以访问。