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

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多平台公布

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理