V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
vinsony
V2EX  ›  NGINX

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

  •  
  •   vinsony · Apr 2, 2019 · 3303 views
    This topic created in 2582 days ago, the information mentioned may be changed or developed.
      location = / {
        add_header loc 2;
      }	
      location / {
        add_header loc 1;
      } 
    

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

    7 replies    2019-04-04 19:25:19 +08:00
    msg7086
        1
    msg7086  
       Apr 2, 2019
    可能是 =/ 里的 index 规则触发了内部 rewrite index.xxx 进了第二个 location。
    vinsony
        2
    vinsony  
    OP
       Apr 3, 2019
    @msg7086 没有什么 rewrite,配置就这么一行
    wosuopu
        3
    wosuopu  
       Apr 3, 2019
    那要看你请求的路径是什么了。
    有一个工具可以在线测试 nginx 的 location 匹配规则的,也许可以用这个试试。https://nginx.viraptor.info/
    vinsony
        4
    vinsony  
    OP
       Apr 3, 2019
    @wosuopu 就请求的首页
    vinsony
        5
    vinsony  
    OP
       Apr 3, 2019
    @wosuopu 这个工具测试没问题,然而 nginx 跑出来的实际结果并不是
    msg7086
        6
    msg7086  
       Apr 3, 2019
    nginx 默认就带了 index index.html,然后 index.html 就会触发 internal redirect,怎么会没有呢。
    lslqtz
        7
    lslqtz  
       Apr 4, 2019 via iPhone
    有没有可能是顺序问题…
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6033 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 03:24 · PVG 11:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.