V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wly19960911
V2EX  ›  问与答

[nginx] location 嵌套,以及匹配规则问题。

  •  
  •   wly19960911 · 2018-09-18 14:41:56 +08:00 · 7795 次点击
    这是一个创建于 2018 天前的主题,其中的信息可能已经有所发展或是发生改变。

    location "/server/" is outside location ".*\.(html)"

    报错如上。

         location ~.*\.(html) {
    
                
                location  /server/ {
                    add_header Cache-Control no-store,must-revalidate;
                    add_header test test1;
                }
                location  /client/ {
                    add_header Cache-Control no-store,must-revalidate;
                    add_header test test2;
                }
            }
    

    报错的话解释很明确了,但是有个奇怪的情况是,如果我换成了 location ~ /client/ 的话,也就是加了 ' ~ '就不会报错了,求问为什么这两种方式会出现这个差异。

    第 1 条附言  ·  2018-09-18 16:52:40 +08:00
    是我看漏了,~ 开头的正则表达式。
    2 条回复    2018-09-18 16:46:57 +08:00
    SakuraKuma
        1
    SakuraKuma  
       2018-09-18 16:36:17 +08:00   ❤️ 1
    ~ 是正则
    wly19960911
        2
    wly19960911  
    OP
       2018-09-18 16:46:57 +08:00
    @SakuraKuma 看来是被网上的教程误解了,到时候我翻翻官方文档看看,最近都没啥时间。感谢回答。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1385 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:42 · PVG 07:42 · LAX 16:42 · JFK 19:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.