Nginx Authentication Module Ngx_http_auth_basic_module

Source: Internet
Author: User

Ngx_http_auth_basic_module module based on "HTTP Basic Authentication" The protocol completes the user authentication.

Module instruction:

Auth_basic

Auth_basic_user_file

The scope of application of these two directives: http , Server , Location , limit_except

Example:

Location/{

Auth_basic "Closedsite";

AUTH_BASIC_USER_FILECONF/HTPASSWD;

}

Auth_basic directive:

Syntax:auth_basic string | off;

Default:auth_basic off;

Open / Close based on "HTTP Basic Authentication" the user of the Agreement / Password Authentication.

Auth_basic_user_file directive:

Syntax:auth_basic_user_file file;

Default:--

Used to specify the file to save the user name and password, and note the file permissions .

The file format is:

Name1:password1

Name2:password2:comment

Name3:password3

Supported Password types:

    • Encrypted with the crypt () function, the tool has htpasswd, OpenSSL passwd

    • Apache Variant (APR1) using MD5-based cryptographic algorithms

Using HTPASSWD to achieve NGINX certification

    1. Installing HTPASSWD,HTPASSWD is the password generation tool provided by Apache

Yuminstall httpd-tools-y

    1. htpasswd usage

$ htpasswd-h

Htpasswd:illegal option--H

Usage:

HTPASSWD[-CIMBDPSDV] [-C Cost] passwordfile username

HTPASSWD-B[CMBDPSDV] [-C Cost] passwordfile username password

HTPASSWD-N[IMBDPS] [-C cost] Username

HTPASSWD-NB[MBDPS] [-C Cost] username password

-C Createa new file.

-N-Don ' tupdate file; Display results on stdout.

-B usethe password from the command line rather than prompting for it.

-I readpassword from stdin without verification (for script usage).

-M ForceMD5 Encryption of the password (default).

-B forcebcrypt Encryption of the password (very secure).

-C setthe Computing time used for the bcrypt algorithm

(Higheris more secure and slower, Default:5, Valid:4 to 31).

-D forcecrypt Encryption of the password (8 chars max, insecure).

-S Forcesha encryption of the password (insecure).

-P Donot Encrypt the password (plaintext, insecure).

-d deletethe specified user.

-V VerifyPassword for the specified user.

    1. Create a user password file

[email protected] ~]$ htpasswd-c /etc/nginx/passwd.db xiaoming # # # New password file creation

New Password:

Re-type New Password:

Adding Password for user xiaoming

[email protected] ~]$ htpasswd /etc/nginx/passwd.db Xiaoli # # # Add a new user

New Password:

Re-type New Password:

Adding Password for user Xiaoli

[email protected] ~]$ cat /etc/nginx/passwd.db # # # View file content formats

Xiaoming: $apr 1$OLMGWTMD$KG6FMWRQZCWEJGT/UWXSJ.

Xiaoli: $apr 1$unkijchm$5h6gigl1q.izbq6yodzav1

    1. Configure Nginx

Location/{

Auth_basic "Welcome";

auth_basic_user_file/etc/nginx/passwd.db;

}

    1. Access to relevant content will be certified

      650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/08/B3/wKiom1nl1oSDZw2SAAAZ63BET1Y888.png "title=" Tim picture 20171017180650.png "alt=" Wkiom1nl1osdzw2saaaz63bet1y888.png "/>

      Use the corresponding user name password to log in to access.


Nginx Authentication Module Ngx_http_auth_basic_module

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.