nginx basic auth

2019-10-04

安装htpasswd工具

#	[RHEL/CentOS]
   sudo yum install httpd-tools	
#[Debian/Ubuntu]
 sudo apt install apache2-utils	

生成密码文件

htpasswd -c /etc/nginx/authfile username

image

编辑nginx.conf

image

添加

 auth_basic           "closed site";
    auth_basic_user_file /etc/nginx/authfile;

重启nginx服务

systemctl restart nginx