nginx
主页 > 服务器 > nginx >

Nginx中root与alias区别介绍

2022-08-20 | 佚名 | 点击:

Nginx中配置文件路径有两种方式,一种是root一种是alias,那么两种有什么区别呢,下面请跟我

Nginx中配置文件路径有两种方式,一种是root一种是alias,那么两种有什么区别呢,下面请跟我一起正确的使用root和alias吧

首先还是先说下他俩的区别,主要是对URI部分处理的不同,如下:

项目结构

Nginx 目录结构如下:html下为部署的前端项目页面,分别为zuiyu和test,下面我将通过使用root和alias来访问

1

2

3

4

5

6

7

8

9

10

nginx

    --conf

    --logs

    --html

      --zuiyu

        --index.html

        --static

      --test

        --index.html

        --static

测试

访问zuiyu项目

1

2

3

4

5

6

7

8

location /zuiyu {

  root html;

  index index.html;

}

location /zuiyu {

  alias html/zuiyu;

  index index.html;

}

访问test项目

1

2

3

4

5

6

7

8

location /test {

   root html;

   index index.html;

 }

 location /test {

   alias html/test;

   index index.html;

 }

总结

通过上面两个小例子,相信大家也已经看出来root和alias的区别了,不错alias就是别名,也就是使用alias配置项目地址的时候,可以直接配置到访问的项目文件夹,而使用root配置时,Nginx 会在的默认部署路径html下找到匹配uri中的文件夹,然后在该文件夹下查找index.html

原文链接:https://www.cnblogs.com/zuiyu/p/16607492.html
相关文章
最新更新