首页 > 系统服务 > 详细

Linux- Nginx用户认证

时间:2018-11-27 16:23:23      阅读:131      评论:0      收藏:0      [点我收藏+]
vim /usr/local/nginx/conf/vhost/test.com.conf//写入如下内容
server
{
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /data/wwwroot/test.com;

location /
{
auth_basic "Auth"; #定义用户认证的名字
auth_basic_user_file /usr/local/nginx/conf/htpasswd; #用户名密码所在路径
}
}

? yum install -y httpd
? htpasswd -c /usr/local/nginx/conf/htpasswd aming #-c 生成这个文件,并指定aming用户,创建第二个时,就不要-c
技术分享图片
? -t && -s reload //测试配置并重新加载 #当你的配置文件有错误时,实际不会生效,
技术分享图片

? mkdir /data/wwwroot/test.com
? echo “test.com”>/data/wwwroot/test.com/index.html
? curl -x127.0.0.1:80 test.com -I//状态码为401说明需要验证
? curl -uaming:passwd 访问状态码变为200
? 编辑windows的hosts文件,然后在浏览器中访问test.com会有输入用户、密码的弹窗
? 针对目录的用户认证
location /admin/
{
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}
访问某个目录
技术分享图片
针对某个文件
技术分享图片

Linux- Nginx用户认证

原文:http://blog.51cto.com/13451715/2322351

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!