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

nginx 的 location 配置难道不是 =/ 优先级最高吗?

  •  
  •   vinsony · 2019-04-02 17:07:18 +08:00 · 2385 次点击
    这是一个创建于 1822 天前的主题,其中的信息可能已经有所发展或是发生改变。
      location = / {
        add_header loc 2;
      }	
      location / {
        add_header loc 1;
      } 
    

    为啥我像上面这样配,header 里面 loc 会为 1 啊???

    7 条回复    2019-04-04 19:25:19 +08:00
    msg7086
        1
    msg7086  
       2019-04-02 23:38:17 +08:00
    可能是 =/ 里的 index 规则触发了内部 rewrite index.xxx 进了第二个 location。
    vinsony
        2
    vinsony  
    OP
       2019-04-03 08:32:47 +08:00
    @msg7086 没有什么 rewrite,配置就这么一行
    wosuopu
        3
    wosuopu  
       2019-04-03 10:17:40 +08:00
    那要看你请求的路径是什么了。
    有一个工具可以在线测试 nginx 的 location 匹配规则的,也许可以用这个试试。https://nginx.viraptor.info/
    vinsony
        4
    vinsony  
    OP
       2019-04-03 10:23:57 +08:00
    @wosuopu 就请求的首页
    vinsony
        5
    vinsony  
    OP
       2019-04-03 10:30:44 +08:00
    @wosuopu 这个工具测试没问题,然而 nginx 跑出来的实际结果并不是
    msg7086
        6
    msg7086  
       2019-04-03 23:12:11 +08:00
    nginx 默认就带了 index index.html,然后 index.html 就会触发 internal redirect,怎么会没有呢。
    lslqtz
        7
    lslqtz  
       2019-04-04 19:25:19 +08:00 via iPhone
    有没有可能是顺序问题…
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:45 · PVG 05:45 · LAX 14:45 · JFK 17:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.