V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
holinhot
V2EX  ›  NGINX

nginx 如何限制某人地区的不法访问

  •  
  •   holinhot · 2015-05-16 16:50:25 +08:00 · 4031 次点击
    这是一个创建于 3274 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如限制只有广东省内的用户才能打开
    其他地区一律拒绝连接

    17 条回复    2015-05-16 20:48:58 +08:00
    shiniv
        1
    shiniv  
       2015-05-16 16:56:33 +08:00
    用 GeoIP
    Septembers
        2
    Septembers  
       2015-05-16 16:58:18 +08:00
    see http://nginx.org/en/docs/http/ngx_http_geo_module.html

    无论用什么IP库都存在误杀概率
    lshero
        3
    lshero  
       2015-05-16 16:59:07 +08:00
    --with-http_geoip_module

    但是geoip对二级运营商地域判断不是很准
    holinhot
        4
    holinhot  
    OP
       2015-05-16 17:01:46 +08:00
    @lshero 到省就可以了
    holinhot
        5
    holinhot  
    OP
       2015-05-16 17:02:38 +08:00
    @shiniv
    @Septembers
    geoip对国内省份好像不太准
    lshero
        6
    lshero  
       2015-05-16 17:13:21 +08:00
    @holinhot 是的,但是是最快捷的办法了,比如北京有一家做企业专线的叫做光环新网geoip基本都识别为河北廊坊
    hiboshi
        7
    hiboshi  
       2015-05-16 19:15:58 +08:00
    dns 分省解析可以么
    holinhot
        8
    holinhot  
    OP
       2015-05-16 19:26:13 +08:00
    @hiboshi 我是要从服务器上严格限制,dns那太自由了 改个hosts就能访问了
    holinhot
        9
    holinhot  
    OP
       2015-05-16 19:28:27 +08:00
    @lshero 我想要是只允许某个省的电信用户访问就好了
    jsthon
        10
    jsthon  
       2015-05-16 19:32:45 +08:00 via Android
    @holinhot 我想到了为什么不直接从DNS入手呢?禁止访问的地区/线路直接解析到127.0.0.1。
    jsthon
        11
    jsthon  
       2015-05-16 19:34:59 +08:00 via Android
    @jsthon 抱歉,楼上已经说明了。那这样的话,搜索引擎收录也会影响喔,这样要突破封锁就只能用代理之类了吧。
    lianyue
        12
    lianyue  
       2015-05-16 19:35:44 +08:00
    http://ip.taobao.com 准确率蛮高的 有api
    holinhot
        13
    holinhot  
    OP
       2015-05-16 19:56:41 +08:00
    @jsthon 要的就是这个效果啊
    holinhot
        14
    holinhot  
    OP
       2015-05-16 19:57:12 +08:00
    @lianyue nginx有模块?
    holinhot
        15
    holinhot  
    OP
       2015-05-16 20:06:13 +08:00
    @shiniv
    @Septembers
    @hiboshi
    @lshero
    @hiboshi
    @jsthon
    @lianyue

    能在iptables上限制吗 区域外的ip直接拦截
    lincanbin
        16
    lincanbin  
       2015-05-16 20:21:30 +08:00
    @holinhot iptables当然可以,但是能精确到运营商的IP库不多,而且收费的居多。
    aalska
        17
    aalska  
       2015-05-16 20:48:58 +08:00
    。。。。。。。。ipip不是有api 获取ip还可以 在chromium可以支持API获取大致经纬度,时区么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2219 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:41 · PVG 23:41 · LAX 08:41 · JFK 11:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.