The setting method of Nginx Directory password protection _nginx

Source: Internet
Author: User
Tags crypt password protection

Then add in the corresponding Server section in the nginx.conf file

Location ^~/test/{
Auth_basic Test-login;
AUTH_BASIC_USER_FILE/ROOT/HTPASSWD;

Then/root/create a new file in the home directory of root htpasswd
The writing format for this file is
User name: Password
One account per line
And the password must be encrypted using the function crypt (3)

The official file says you can use Apache's htpasswd tool to create password files.
Of course, you can create a new pw.pl file with Perl by creating a password file that reads:

Copy Code code as follows:

#!/usr/bin/perl
Use strict;

My $pw = $ARGV [0];
Print crypt ($PW, $PW). " n ";

Then execute chmod +x pw.pl
./pw.pl Password
Papaq5pwy/qqm
PAPAQ5PWY/QQM is Password's crypt () password.
And then the encrypted password, which is generated with Perl,
According to
User name: Password
The format is written to the htpasswd file

This completes the setup

If you don't
^~/test/
And with
/test
Then the directory will only be authenticated. Direct access to files under it will not eject logon verification

And htpasswd, the name of this file can be set at your own discretion.
User name is also set at your own discretion without encryption
Password must be encrypted using function crypt (3)

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.