Nginx Configuration Basic Authentication

Source: Internet
Author: User

/**/

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.