nginx basic auth

1
2
3
sudo yum install -y httpd-tools # centos
apt install -y apache2-utils # ubuntu
htpasswd -c /usr/local/openresty/nginx/conf/htpasswd <username>

nginx.conf

1
2
3
4
5
6
server {
......
auth_basic "Private Property";
auth_basic_user_file /usr/local/openresty/nginx/conf/htpasswd;
......
}

重启 nginx

1
systemctl reload nginx