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 · 4236 views
    This topic created in 2694 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
        1
    jayong  
       Jan 25, 2019
    前两个 if 加 break 试试
    mN71eOOprFyMsnPx
        2
    mN71eOOprFyMsnPx  
       Jan 25, 2019
    你这样解决太复杂了。这样:

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

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