Use nginx as the front-end server. Some resources must be protected. HTTP auth basic authentication is simple and convenient. The HTTP auth basic password of nginx is encrypted with Crypt (3. Specific can refer to: http://wiki.nginx.org/HttpAuthBasicModule
Take a simple background management as an example. The address is http: // xxxx/admin/* to manage the permissions of the files under admin;
1. Enter the ngnix configuration address. Take my Ubuntu as an example; CD/etc/ngnix
2. Run the following command to generate the passfile:Htpasswd-c-d/etc/nginx/pass_file Username
A. Enter the preceding command, press enter to enter the password, press enter again, and enter Confirm Password.
3. Check whether pass_file already exists/etc/ngnix/pass_file
4. Modify ngnix Configuration
Location ~ /Admin {
Auth_basic "restricted ";
Auth_basic_user_file/etc/nginx/pass_file; // use the absolute path.
Root/home/www/admin; // host address. Otherwise, the corresponding file cannot be found after the authentication is passed.
}
5. Restart ngnix and sudo service ngnix reload;
6. log on to http: // xxxx/admin/*. The verification box is displayed, indicating that the verification configuration is complete.
If php exists in admin, php URL cannot be properly parsed. We need to reconfigure the configuration as follows:
Location ~ /Admin {
Auth_basic "restricted ";
Auth_basic_user_file/etc/nginx/pass_file; // use the absolute path.
Root/home/www/admin; // host address. Otherwise, the corresponding file cannot be found after the authentication is passed.
If ($ request_filename ~ *. Php)
{
Fastcgi_pass 127.0.0.1: 9000;
} // The following files cannot be placed in brackets; otherwise, an error is reported.
Fastcgi_index index. php;
Fastcgi_param script_filename/home/www/ADMIN $ fastcgi_script_name; // The path is the same as root
Include fastcgi_params;
}
Modify the configuration and restart ngnix. The php file is displayed normally.