关于后端:Nginx中root与alias区别

8次阅读

共计 610 个字符,预计需要花费 2 分钟才能阅读完成。

Nginx 中配置文件门路有两种形式,一种是 root 一种是 alias,那么两种有什么区别呢,上面请跟我一起正确的应用rootalias

首先还是先说下他俩的区别,次要是对 URI 局部解决的不同,如下:

我的项目构造

Nginx 目录构造如下:html下为部署的前端我的项目页面, 别离为 zuiyutest,上面我将通过应用 rootalias来拜访

  nginx
    --conf
    --logs
    --html
      --zuiyu
        --index.html
        --static
      --test
        --index.html
        --static

测试

  • 拜访 zuiyu 我的项目
  location /zuiyu {
    root html;
    index index.html;
  } 
  location /zuiyu {
    alias html/zuiyu;
    index index.html;
  } 
  • 拜访 test 我的项目
  location /test {
    root html;
    index index.html;
  } 
  location /test {
    alias html/test;
    index index.html;
  } 

总结

通过下面两个小例子,置信大家也曾经看进去 rootalias的区别了,不错 alias 就是别名,也就是应用 alias 配置我的项目地址的时候,能够间接配置到拜访的我的项目文件夹,而应用 root 配置时,Nginx 会在的默认部署门路 html 下找到匹配 uri 中的文件夹,而后在该文件夹下查找index.html

本文由 mdnice 多平台公布

正文完
 0