/**/
Configuring Basic authentication under Nginx requires an Nginx http_auth_basic_module module (Official document: Http://nginx.org/en/docs/http/ngx_http_auth_basic_ module.html)
Configuration process:
① generate authentication file in the form of user name: password
Password is encrypted by crypt (username: User, password: 123456)
The file is saved under/usr/local/nginx/conf
Generate File:
" user:$ (OpenSSL passwd-crypt 123456) \ n " >>htpasswd
To view the file:
② Configure the/usr/local/nginx/conf/nginx.conf file and add Auth_basic and Auth_basic_user_file to the location segment:
Location \ { "login"; auth_basic_user_file/usr/local/nginx/conf/htpasswd; }
Where Auth_basic is the pop-up prompt, you can customize
Auth_basic_user_file is the path to the authentication file, the absolute path can be written, or the file name can be written only (the default path is/usr/local/nginx/conf)
Smooth restart Nginx.
At this time access 192.168.254.100, prompt authentication:
If you enter an error, the popup will continue to pop up;
If you cancel the input, the response 401 Unauthorized:
If the input is correct, the response is OK.
Reference:
Http://blog.chenlb.com/2010/03/nginx-http-auth-basic.html
Http://www.jb51.net/article/32211.htm
Http://os.51cto.com/art/201308/407232.htm
Nginx Configuration Basic Authentication