nginx 访问限制和基本认证(BASIC)
在 nginx 配置中,对需要保护的站点配置文件中你需要做如下配置:
auth_basic 提供密码保护域的名称
auth_basic_user_file 指定包含用户密文的证书的文件
(.htpasswd
)
ubuntu
apt install apache2-utils htpasswd -c /etc/nginx/.htpasswd nico #nico为输入的用户名

centos
yum install httpd-tools htpasswd -c /etc/nginx/.htpasswd nico #nico为输入的用户名
nginx应用配置
server{}中添加下面的配置
auth_basic "Administrator Area"; auth_basic_user_file /etc/nginx/.htpasswd;
效果


