• nginx location 限制ip或ip段访问


    指定目录的IP访问限制

    实现重点

    正则表达式中()和|的使用,()代表一个原则,|代表或
    nginx的location匹配规则中,有一条按照文件顺序进行正则匹配(ps:可以把需要匹配的目录放置在server模块开始的位置)
    allow和deny的使用


    实现的nginx配置文件

    #指定目录实行白名单访问机制
    location ~ ^/(test1|test2)/ {
    allow 192.168.1.101;
    deny all;

    root /srv/;
    fastcgi_param HTTPS on;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass php5_fpm;
    }

    # proxy the PHP scripts to fpm
    location ~ .php$ {
    root /srv/;
    fastcgi_param HTTPS on;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass php5_fpm;
    }

    注意事项:
      1. deny 一定要加一个ip,否则直接跳转到403,不往下执行了;如果403默认页是同一域名下,会造成死循环访问;
      2. allow的ip段
      从允许访问的段位从小到大排列,如127.0.0.0/24 下面才能是10.10.0.0/16
      24表示子网掩码:255.255.255.0
      16表示子网掩码:255.255.0.0
      8表示子网掩码:255.0.0.0
      3. deny all;结尾 表示除了上面allow的其他都禁止
    如:

    复制代码 代码如下:
    deny 192.168.1.1;
    allow 127.0.0.0/24;
    allo w 192.168.0.0/16;
    allow 10.10.0.0/16;
    deny all;

  • 相关阅读:
    vue-指令
    VueMusic-14搜索实现
    VueMusic-13歌手列表
    VueMusic-12歌词滚动
    VueMusic-11播放-歌词适配
    VueMusic-10.播放-歌词加载
    VueMusic-9.播放-播放功能
    VueMusic-8更多-下拉刷新
    VueMusic-7更多-数据适配
    VueMusic-6首页-热门榜单
  • 原文地址:https://www.cnblogs.com/rutor/p/10917895.html
Copyright © 2020-2023  润新知