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

nginx 如何多站点配置屏蔽 geo?

  •  
  •   178620086 · 2019-10-16 13:33:35 +08:00 · 2886 次点击
    这是一个创建于 1625 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我知道可以在 server 节点下面配置

    if ($geoip_country_code = JP) { return 403; }

    请问能在 http 下配置吗?或者有其他方式可以实现,多个 server 都实现这个拦截

    6 条回复    2019-10-16 19:33:13 +08:00
    lihongjie0209
        1
    lihongjie0209  
       2019-10-16 13:42:01 +08:00
    include 不行吗???
    178620086
        2
    178620086  
    OP
       2019-10-16 15:13:48 +08:00
    虽然也可以,但是我每次新增一个 server 就要配置一下,怪麻烦的
    yutian2211
        3
    yutian2211  
       2019-10-16 15:42:15 +08:00
    Syntax: if (condition) { ... }
    Default: —
    Context: server, location

    不可以放到 http 下
    flyingghost
        4
    flyingghost  
       2019-10-16 16:25:06 +08:00
    前置一个 nginx 反代专做过滤。
    Nick66
        5
    Nick66  
       2019-10-16 16:34:14 +08:00
    if 不能写在 http 区块
    eason1874
        6
    eason1874  
       2019-10-16 19:33:13 +08:00
    用 lua-nginx-module 可以直接在 http 段写访问控制。

    access_by_lua_block {
    if ngx.var.geoip_country_code == 'JP' then
    ngx.exit(403)
    end
    }

    大概是这样,这个模块非常好用。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4999 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:14 · PVG 09:14 · LAX 18:14 · JFK 21:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.