首页 > 其他 > 详细

nginx基于htpasswd安全验证

时间:2014-02-21 08:10:33      阅读:343      评论:0      收藏:0      [点我收藏+]

工作原因,需要对一个服务做做安全验证,基于nginx负载:

在nginx 做安全验证,在nginx.conf中server标签下添加如下:

       auth_basic "Authorized Login1111";

       auth_basic_user_file /opt/nginx/conf/htpasswd;


     也可以做location 匹配,依照个人需求

       location / {

       auth_basic "Authorized Login1111";

       auth_basic_user_file /opt/nginx/conf/htpasswd;

              }


然后使用htpasswd生成用户和密码(密文)

       /usr/bin/htpasswd -c /opt/nginx/conf/htpasswd user

      New password: ***
             Re-type new password: ***

       cat   /opt/nginx/conf/htpasswd user

            user:pwYOfUEu2Zrls

如果没有htpasswd可以使用类似命令来操作

a=`perl -e ‘print crypt($ARGV[0], "pwdsalt")‘  123456`

echo "user:$a" >/opt/nginx/conf/htpasswd

cat   /opt/nginx/conf/htpasswd user

user:pwy1aR9NQZei6

也可以写成小脚本使用


nginx基于htpasswd安全验证

原文:http://zhangxiaohe.blog.51cto.com/7821029/1361150

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!