工作原因,需要对一个服务做做安全验证,基于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
也可以写成小脚本使用
转载于:https://blog.51cto.com/zhangxiaohe/1361150