安装apache支持的htpasswd
yum -y install httpd
安装完成后查看其路径
[localhost@root ~]$ which htpasswd
[localhost@root ~]$ /usr/bin/htpasswd
生成密码库文件
[root@acgcommittee xiangchen]# htpasswd -c /usr/local/nginx/conf/.htpassed acg
New password: #输入密码
Re-type new password: #再次输入密码
编辑/usr/local/nginx/config/nginx,conf或者nginx的虚拟主机配置文件
添加如下认证配置(示例)
location /
{
root /usr/local/http/admin.php;
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
}
检查nginx配置是否正确
/usr/local/nginx/sbin/nginx -t
yum卸载临时使用的httpd
yum -y remove httpd
原文地址:http://xiangcc.blog.51cto.com/10201823/1700678