Detailed description of access password configuration for Nginx specified directory settings

Source: Internet
Author: User

Create an htpasswd file:

You can use the following python script to generate:

Http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py

Run the following command:

Chmod 777 htpasswd. py
./Htpasswd. py-c-B htpasswd username password

Htpasswd is the generated file name.

2. Modify nginx conf

Modify nginx. conf or the conf of the vhost to be set. Add the following statement:

Location ^ ~ /
{
Auth_basic "Password ";
Auth_basic_user_file/usr/local/nginx/conf/htpasswd;
}

Here, htpasswd is a file generated in the previous step. I put it in the nginx conf folder. In this way, the entire root directory is encrypted, but a problem occurs that php cannot be parsed. Change the php parsing part in the above file:

Location ^ ~ /{
Location ~ . * \. (Php | php5 )? $ {
Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_index index. php;
Fcinclude GI. conf;
}
Auth_basic "Password ";
Uth_basic_user_file/usr/local/nginx/conf/htpasswd;
}

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.