Nginx用户认证配置

which htpasswd  #查看是否安装htpasswd
yum install httpd-tools  #安装htpasswd
 
#生成密码文件
htpasswd -cb /usr/local/tengine/conf/htpasswd 用户名 密码
例:
htpasswd -cb /usr/local/tengine/conf/htpasswd admin 123456
 
chmod 400 /usr/local/nginx/conf/htpasswd  #为了安全设置文件权限
 
 
配置文件:
location ~ /\.ht {
deny all;
auth_basic "Please input password";    //提示词
auth_basic_user_file /usr/local/nginx/conf/htpasswd;   //密码文件的路径
}
 
配置完成后 reload nginx
 

posted @ 2019-09-17 11:51  来自天堂的魔鬼  阅读(292)  评论(0编辑  收藏  举报