› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
178620086
V2EX  ›  NGINX

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

  •  
  •   178620086 · Oct 16, 2019 · 4262 views
    This topic created in 2578 days ago, the information mentioned may be changed or developed.

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

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

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

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

    不可以放到 http 下
    flyingghost
    flyingghost
    Oct 16, 2019
    4
    前置一个 nginx 反代专做过滤。
    Nick66
    Nick66
    Oct 16, 2019
    5
    if 不能写在 http 区块
    eason1874
    eason1874
    Oct 16, 2019
    6
    用 lua-nginx-module 可以直接在 http 段写访问控制。

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

    大概是这样,这个模块非常好用。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2181 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 14:23 · PVG 22:23 · LAX 06:23 · JFK 09:23
    ♥ Do have faith in what you're doing.