Set up access verification for the Site directory after we enter this page will need to enter the authentication password, I would like to introduce the Nginx Directory access authentication Code method summary.
1. Create Class HTPASSWD files
Perform:
Wget-c Soft.vpser.net/lnmp/ext/htpasswd.sh;bash htpasswd.sh
Enter the username, password, and authentication file name as prompted. The script will automatically generate the authentication file. Record the path of the file returned by the script. such as:/usr/local/nginx/conf/vpser.net.auth.
2. Add Auth authentication configuration for Nginx
The following is an example of a soft directory under a domain name that adds the following code to the server section of the domain name:
Copy Code code as follows:
Location ^~/soft/
{
Auth_basic "Authorized users only";
Auth_basic_user_file//Here Write the previous script to return the file path;
}
Authorized users only as a hint of information, you can modify the information you want him to prompt; Auth_basic_user_file need to fill in the Htpasswd.sh script to return the path of someone else's file. After the above prompts to modify the configuration, restart Nginx, access to http://yourdomainname/soft/will prompt you to enter a username and password.
Note that the addition of authentication after the directory of PHP will not be resolved, there will be download prompts, if you want to be able to parse PHP can change the above configuration to:
Copy Code code as follows:
Location ^~/soft/{
Location ~. *. (PHP|PHP5)? $ {
Fastcgi_pass Unix:/tmp/php-cgi.sock;
Fastcgi_index index.php;
Include fcgi.conf;
}
Auth_basic "Authorized users only";
Auth_basic_user_file//Here Write the previous script to return the file path;
}