AerithLoveMe
V2EX  ›  问与答

Nginx location 模块配置问题

  •  
  •   AerithLoveMe · Sep 13, 2021 · 1616 views
    This topic created in 1748 days ago, the information mentioned may be changed or developed.
    目前 Nginx 模块配置如下:

    location ^~ /jenkins

    location ^~ /upload

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

    location ^~ /image/

    为什么我请求 xxx.com/index.html 居然可以请求成功(可以访问 html/index.html ),= 不应该是精准匹配吗?按我理解应该返回 404 not found 吧?
    6 replies    2021-09-13 14:14:35 +08:00
    iBugOne
        1
    iBugOne  
       Sep 13, 2021 via Android
    你是不是在外面*也*配了 root 和 index,如果有的话没匹配到的 location 就会按 server 块里的 root 和 index 处理
    AerithLoveMe
        2
    AerithLoveMe  
    OP
       Sep 13, 2021
    @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  
       Sep 13, 2021 via Android
    你只是默认主页换了 又不影响直接输完整地址访问
    iBugOne
        4
    iBugOne  
       Sep 13, 2021 via Android
    最外层 http 块也有 root 和 index 会生效,也去检查一下吧,一般在 /etc/nginx/nginx.conf 里
    AerithLoveMe
        5
    AerithLoveMe  
    OP
       Sep 13, 2021
    @iBugOne 真的没有了 我全部检查了一遍,进入了这个 server 块,只有这些配置
    AerithLoveMe
        6
    AerithLoveMe  
    OP
       Sep 13, 2021
    @18x 不应该吧 =是精准匹配。我这个 html 下的东西它全部可以访问,那我配置这个没意义了吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2910 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 02:30 · PVG 10:30 · LAX 19:30 · JFK 22:30
    ♥ Do have faith in what you're doing.