nginx实现访问网站或目录密码认证保护

添加目录登陆认证
location  /  {
  auth_basic            "提示";
  auth_basic_user_file  /usr/conf/htpasswd;
}

auth_basic
指令包含一个具有测试用户名和密码的HTTP基本认证,指定的参数将用于认证域。如果将值设置为“off”则忽略下级指令继承的动作。
auth_basic_user_file
指令为验证域指定了密码文件,0.6.7版本以后这里指定的文件是nginx.conf所在目录的绝对路径,而不是–prefix指定的路径。
这个文件格式如下:
user:pass
user2:pass2:comment
user3:pass3

http://tool.oschina.net/htpasswd

 

posted on 2014-07-29 11:42  Love I Smile  阅读(253)  评论(0编辑  收藏  举报