#详细说明# nginx.conf 中 root 目录设置问题


在配置 nginx.conf 总会遇到一些问题,下面列举一些常见的问题并说明如何解决

1、相对路径的问题

例如配置文件中 location 设置

location ~ .php${
root html
}

location 中root所指向的html是一个相对路径,相对的是这个配置文件的路径,假设此配置文件的位置是/etc/nginx/conf.d,那么这个html的绝对路径就是/etc/nginx/conf.d/html。因此为避免出现不必要的麻烦,在配置root路径的过程中最好用绝对路径。

2、路径的继承问题

2.1 第一种情况

假如server 中声明:

root /usr/share;

且 location 中声明:

location /{
root /usr/html/www
}

此时会优先使用 location 中的路径

2.2 第二种情况

假如 location 中未对root路径进行声明:

location /app {

}

则默认使用 location 外的 root 声明的路径

3、首页的设置问题

假如我们在声明server 中声明:

index index.html index.php

那么我们此时请求 / 就会在内部重定向到 url/index.php 或者 url/index.html
然后再由相关的location 进行匹配 之后再进行解析

发布了59 篇原创文章 · 获赞 2 · 访问量 4699

猜你喜欢

转载自blog.csdn.net/lch551218/article/details/104247051