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

nginx 指定 IP 跟指定 user_agent 访问问题

  •  
  •   lixuda · Jan 25, 2019 · 4627 views
    This topic created in 2857 days ago, the information mentioned may be changed or developed.

    网站旗下一个目录或文件需要只允许指定 ip 跟指定 user_agent kmuyVg.png

    但是我这样设置无效,请教大神。 其他用户还是可以访问

    Supplement 1  ·  Jan 26, 2019
    指定 IP 或指定 user_agent 符合一个即可访问
    Supplement 2  ·  Jan 26, 2019
    (指定 IP||指定 UA)
    6 replies  •  2019-01-26 13:33:25 +08:00
    jayong
    jayong
    Jan 25, 2019
    1
    前两个 if 加 break 试试
    mN71eOOprFyMsnPx
    mN71eOOprFyMsnPx
    Jan 25, 2019
    2
    你这样解决太复杂了。这样:

    location ~ /my.php.* {
    if ($http_user_agent !~ "v2ex") {
    return 403;
    }

    allow x.x.x.x;
    deny all;
    }
    shansing
    shansing
    Jan 25, 2019
    3
    @FifiLyu 你这个“与 /或”逻辑跟楼主的代码好像不一样。不知道楼主指的是 (指定 IP||指定 UA) 可访问还是 (指定 IP&&指定 UA)。
    salmon5
    salmon5
    Jan 25, 2019 via Android
    4
    allow 23.100.1.222;
    allow 23.107.17.58;
    allow 23.107.17.59;
    allow 23.107.17.60;
    allow 23.107.17.61;
    allow 23.107.17.62;
    deny all;
    lixuda
    lixuda
    OP
    Jan 26, 2019
    5
    @shansing 是我描述不清,我的目标是 (指定 IP||指定 UA)
    lixuda
    lixuda
    OP
    Jan 26, 2019
    6
    感谢,貌似你这个是指定 IP&&指定 UA 我想要的是 指定 IP||指定 UA
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   899 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:29 · PVG 04:29 · LAX 12:29 · JFK 15:29
    ♥ Do have faith in what you're doing.