Nginx开启Basic_Auth登录认证

Nginx支持直接开启basic auth,开启Basic_Auth登录后客户端需要在请求头部添加Basic_Auth的内容方可继续访问 在nginx配置文件的server段添加以下 server { #… auth_basic “XXXX”; #提示登录文本 auth_basic_user_file conf/htpasswd; #密码文件路径 #… } 两种方式生成basic auth的密码 使用openssl



printf "username:$(openssl passwd -crypt 123456)\n" >>conf/htpasswd

使用htpasswd



#创建
htpasswd -c -d conf/htpasswd username
#修改
htpasswd -b -d conf/htpasswd username passwd