nginx user login authentication
https://blog.csdn.net/endzhi/article/details/88931176
Whether the test has been installed htpasswd
[root@localhost ~]# htpasswd -h
htpasswd command can not find, install httpd-tools,
[root@localhost ~]# yum -y install httpd-tools
htpasswd command to generate the password database files and create user and password
[root@localhost ~]# htpasswd -bc /usr/local/nginx/passwd.db zhangsan 123456
View htpasswd password generated for encrypted format
[root@localhost ~]# cat /usr/local/nginx/passwd.db
Zhang San: $ apr1 $ 3NQgw.Zb $ JWQSENiJ8JzzMDAUGfqGf.
Set requires authentication landing location (valid only for this location)
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
auth_basic "User Authentication"; ## certified pop prompt
auth_basic_user_file /usr/local/nginx/passwd.db; ## password file path
}
Reload the configuration
/usr/local/nginx/sbin/nginx -s reload
Browser to access test
wget and curl with the account password to access the resource format
wget --http-user=zhangsan --http-passwd=123456 http://192.168.1.100
curl -uzhangsan:123456 http://192.168.1.100
htpasswd use
1. Increase user
htpasswd -b /usr/local/nginx/passwd.db admin 123456
Be careful not to have c, reset the password database files only with c.
2. Modify the user password
Mode 1 htpasswd -b /usr/local/nginx/passwd.db admin 123eee
We will update the original user password
Way 2 htpasswd -nb admin 123eee
After displaying the encrypted string of code, edit the code library file, modified
3 Delete the user.
Mode 1 htpasswd -D /usr/local/nginx/passwd.db admin
2 Edit mode password database file, delete the user line.
windows version of nginx configuration
auth_basic "User Authentication"; ## certified pop prompt
auth_basic_user_file D: /app/nginx-1.17.3/conf/passwd; ## configured as a path backslash.
user password passwd file content in the following format:
username: 123456
----------------
Disclaimer: This article is the original article CSDN bloggers "endzhi", and follow CC 4.0 BY-SA copyright agreement , reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/endzhi/article/details/88931176