Nginx -- 访问控制

访问控制,就是只让某些ip访问,

基于IP :

根目录下创建 二级目录a ,

  [root@oldboy--01 nginx]# cd html
  [root@oldboy--01 html]# ls
    50x.html a b index.html web01 web02

 

location /a {
  allow 10.0.0.200;            #只允许本机ip(10.0.0.200)访问,其他ip访问返回404
   deny all;              #拒绝所有
   return 404;                 #返回404

   return img            #返回图片

   return 503           #迷惑敌人

}

物理机访问 10.0.0.200/a,被限制

基于账号密码:

下载依赖包:yum -y install httpd-tools

  

etc配置文件创建账号目录:mkdir /etc/nginx/htpasswd

  

创建用户

  

nginx.conf创建二级路径和验证信息

  

根目录创建二级文件b

  


实现登录验证,如果登不上去,就是密码没有加密

  

创建加密用户

  

查看创建的用户:vim /etc/nginx/htpasswd sky

  


成功登录

   

猜你喜欢

转载自www.cnblogs.com/sunny666/p/11057876.html