通过nginx让用户输入用户名密码认证访问web页面

sudo htpasswd -c /usr/local/nginx/passwd.db karl
sudo chmod 755 /usr/local/nginx/passwd.db
sudo chown root:root /usr/local/nginx/passwd.db
sudo cat /usr/local/nginx/passwd.db
server {
     listen       8081;
     server_name  localhost;
     client_max_body_size    151m;
     location / {
         auth_basic "s1";  #虚拟主机认证命名
         auth_basic_user_file /usr/local/nginx/passwd.db; #虚拟主机用户名密码认证数据库
         proxy_pass http://127.0.01:4000;  # nodejs gitbook
         root   html;
         index  index.html index.htm;
     }
}
sudo nginx -s reload
Ref:

https://blog.csdn.net/wyl9527/article/details/72598112

Search

    Table of Contents