Note

Nginx 静态页面与路径配置

nginx location [PATTERN] 默认 / 指定为 nginx 文件夹下的 html 文件夹
如果 [PATTERN] 使用了其他值 /test ,不使用绝对路径的话,则会默认指向 nginx 文件夹下的 html 文件夹下面的 test 文件夹


# / 指向 /usr/local/nginx/html
  location / {
    root   html;
    #index  index.html index.htm;
    index  yu-index.html;
    charset utf-8;
  }

# /test 指向 /usr/local/nginx/html/test
  location /test {
    root   html;
    index  test.html;
    charset utf-8;
  }
...
...
...
Replying to @0x663

这个描述可能并不准确。

在你的 Nginx 配置中,location 块通过 root 指令定义了 root 路径为相对路径 html,当 root 指令使用相对路径时,实际上是相对于 nginx 编译时定义的 prefix 目录。这个 prefix 目录可以执行 nginx -V,然后在输出的 configure arguments: --prefix=<prefix> 中查看到。在你的 Nginx 里面,可能 prefix 路径正是 /usr/local/nginx,再加上 location 块中指定的 root html;,导致最终请求指向的根目录是 /usr/local/nginx/html

最终访问到的文件是根目录路径和 HTTP 请求中 URI 部分的组合。所以请求 /test 指向 /usr/local/nginx/html/test

0
0
...
...
...
Avatar