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

请教一下,为什么 nginx 的 try_files 在使用 if 过后无效?

  •  
  •   zhaoyc2018 · 2019-04-01 09:36:31 +08:00 · 2852 次点击
    这是一个创建于 1845 天前的主题,其中的信息可能已经有所发展或是发生改变。
    location ~ "/test-p15990\.html$" {
    if ( $whitelist = 0 ) {
    set $test 1;
    }

    default_type "text/html; charset=UTF-8";

    add_header debug "test1";

    try_files /html/p15/990 =404;
    }

    注销第 2 和第 4 行就正常返回页面,说明设置变量没有问题,如果$whitelist 为 1 时是正常的。

    但问题是当$whitelist 为 0 时就不行了呢?
    5 条回复    2019-04-01 13:22:59 +08:00
    uncat
        1
    uncat  
       2019-04-01 09:48:56 +08:00 via iPhone
    优先级问题,后者高
    zhaoyc2018
        2
    zhaoyc2018  
    OP
       2019-04-01 09:58:24 +08:00
    优先级?没搞懂 @uncat
    mcfog
        3
    mcfog  
       2019-04-01 11:10:35 +08:00
    no1xsyzy
        4
    no1xsyzy  
       2019-04-01 11:29:09 +08:00
    我猜应该是 try_files 没有被 if 配置块继承。
    zhaoyc2018
        5
    zhaoyc2018  
    OP
       2019-04-01 13:22:59 +08:00
    add_header 也没有用,看来就是 @mcfog 所说的问题。。。

    谢谢各位
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2415 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:04 · PVG 00:04 · LAX 09:04 · JFK 12:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.