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

Nginx location 模块配置问题

  •  
  •   AerithLoveMe · 2021-09-13 13:15:02 +08:00 · 793 次点击
    这是一个创建于 928 天前的主题,其中的信息可能已经有所发展或是发生改变。
    目前 Nginx 模块配置如下:

    location ^~ /jenkins

    location ^~ /upload

    location = / {
    root html;
    index welcome.html;
    }

    location ^~ /image/

    为什么我请求 xxx.com/index.html 居然可以请求成功(可以访问 html/index.html ),= 不应该是精准匹配吗?按我理解应该返回 404 not found 吧?
    6 条回复    2021-09-13 14:14:35 +08:00
    iBugOne
        1
    iBugOne  
       2021-09-13 13:17:41 +08:00 via Android
    你是不是在外面*也*配了 root 和 index,如果有的话没匹配到的 location 就会按 server 块里的 root 和 index 处理
    AerithLoveMe
        2
    AerithLoveMe  
    OP
       2021-09-13 13:22:07 +08:00
    @iBugOne 并没有 我剩下的只配了 error_page 404 /error.html;
    location = /error.html {
    root html;
    }

    error_page 403 /403.html;
    location = /403.html {
    root html;
    }

    还有就是其它域名的 server,和这个匹配无关
    18x
        3
    18x  
       2021-09-13 13:40:52 +08:00 via Android
    你只是默认主页换了 又不影响直接输完整地址访问
    iBugOne
        4
    iBugOne  
       2021-09-13 14:02:35 +08:00 via Android
    最外层 http 块也有 root 和 index 会生效,也去检查一下吧,一般在 /etc/nginx/nginx.conf 里
    AerithLoveMe
        5
    AerithLoveMe  
    OP
       2021-09-13 14:12:56 +08:00
    @iBugOne 真的没有了 我全部检查了一遍,进入了这个 server 块,只有这些配置
    AerithLoveMe
        6
    AerithLoveMe  
    OP
       2021-09-13 14:14:35 +08:00
    @18x 不应该吧 =是精准匹配。我这个 html 下的东西它全部可以访问,那我配置这个没意义了吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5399 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.