创建密码认证文件

#yum install apache2-utils
#htpasswd -c /opt/nginx/conf/admin_pass admin   #admin为用户名
New password: 
Re-type new password: 
Adding password for user admin

 

server {} 里加入以下内容:

认证 http://192.168.1.100/admin 目录访问

location ~*  ^/admin {
    auth_basic "admin";
    auth_basic_user_file /opt/nginx/conf/admin_pass;
    include /opt/nginx/conf/enable_php.conf;
}


认证 http://192.168.1.100/admin.php 文件访问

location ~*  ^/admin.php?$ {
    auth_basic "admin";
    auth_basic_user_file /opt/nginx/conf/admin_pass;
    include /opt/nginx/conf/enable_php.conf;
 }