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;
}