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 · 3858 views
    This topic created in 2400 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
        1
    lihongjie0209  
       Oct 16, 2019
    include 不行吗???
    178620086
        2
    178620086  
    OP
       Oct 16, 2019
    虽然也可以,但是我每次新增一个 server 就要配置一下,怪麻烦的
    yutian2211
        3
    yutian2211  
       Oct 16, 2019
    Syntax: if (condition) { ... }
    Default: —
    Context: server, location

    不可以放到 http 下
    flyingghost
        4
    flyingghost  
       Oct 16, 2019
    前置一个 nginx 反代专做过滤。
    Nick66
        5
    Nick66  
       Oct 16, 2019
    if 不能写在 http 区块
    eason1874
        6
    eason1874  
       Oct 16, 2019
    用 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   ·   Solana   ·   5749 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 118ms · UTC 01:44 · PVG 09:44 · LAX 18:44 · JFK 21:44
    ♥ Do have faith in what you're doing.