v2-765d13f518f3204c63ad129b41e52119_r.jpg
server配置

server {
        listen 80;
        server_name 192.168.241.130 10.0.0.3;

        root /data/nginx/html;
        index index.html;

        location / {
                auth_basic "auth test";#认证界面命名信息
                auth_basic_user_file auth/htpasswd;
                autoindex on;
        }
}

密码生成,用openssl或者htpasswd

[root@db ~]# printf "test:$(openssl passwd -crypt test)\n" >>auth/htpasswd

或者:

[root@db ~]# yum install -y httpd-tools
[root@db ~]# htpasswd -c htpasswd test  #创建test用户
New password: 
Re-type new password: 
Adding password for user test
[root@db ~]# cat htpasswd 
test:4qJ2CefvLVpOk
[root@db ~]# htpasswd htpasswd test1    #增加用户
New password: 
Re-type new password: 
Adding password for user test1
[root@db ~]# cat htpasswd 
test:4qJ2CefvLVpOk
test1:/jR3q9umOQdTw

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code