nginx用户认证ngx_http_auth_basic_module
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