nginx 用户认证

在nginx虚拟主机中添加:
location ~ .*admin.php$ {
auth_basic “grapedlinux auth”;
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}

并用htpasswd工具生成密码文件:
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/.htpasswd graped

这样便只有在输入账户密码后才可以访问。