wly19960911
V2EX  ›  问与答

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

  •  
  •   wly19960911 · Sep 18, 2018 · 8777 views
    This topic created in 2835 days ago, the information mentioned may be changed or developed.

    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/ 的话,也就是加了 ' ~ '就不会报错了,求问为什么这两种方式会出现这个差异。

    Supplement 1  ·  Sep 18, 2018
    是我看漏了,~ 开头的正则表达式。
    2 replies    2018-09-18 16:46:57 +08:00
    SakuraKuma
        1
    SakuraKuma  
       Sep 18, 2018   ❤️ 1
    ~ 是正则
    wly19960911
        2
    wly19960911  
    OP
       Sep 18, 2018
    @SakuraKuma 看来是被网上的教程误解了,到时候我翻翻官方文档看看,最近都没啥时间。感谢回答。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   905 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:07 · PVG 05:07 · LAX 14:07 · JFK 17:07
    ♥ Do have faith in what you're doing.