1 安装相关包
1
|
yum install -y httpd-tools
|
2 创建校验文件
1
2
3
|
htpasswd -cb /etc/nginx/ .htpasswd user1 'passwd1'
chown nginx:nginx /etc/nginx/ .htpasswd
chmod 400 /etc/nginx/ .htpasswd
|
3 加载校验文件
1
|
vim /etc/nginx/nginx .conf
|
加入如下信息:
1
2
3
4
5
|
server { [...]
auth_basic "Restricted" ;
auth_basic_user_file /etc/nginx/ .htpasswd;
} |
重载配置文件:
1
|
/etc/init .d /nginx reload
|
4 测试认证
1
|
curl http: //user1 :passwd1@192.168.0.5
|
本文转自 tanzhenchao 51CTO博客,原文链接:http://blog.51cto.com/cmdschool/1948648,如需转载请自行联系原作者