美文网首页
Nginx中root与alias区别

Nginx中root与alias区别

作者: 醉鱼java | 来源:发表于2022-08-19 12:15 被阅读0次

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

相关文章

  • Nginx的root和alias

    nginx指定文件路径有两种方式root和alias root alias root与alias主要区别在于ngi...

  • Nginx虚拟目录alias和root目录

    nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的:1)alia...

  • nginx

    nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的: 1)ali...

  • 知识汇总

    alias与root的区别 root的用法 alias的用法 alias不会把location匹配的路径带上,root会

  • Nginx alias root 区别

    alias与root都可以指向到静态文件 root 如果访问 /demo1/a.jpg,实际访问的是 /www/h...

  • Nginx虚拟目录alias和root的区别

    nginx中alias标签和root标签到底有哪些区别呢? 1.alias指定的目录是location匹配访问的p...

  • nginx的location、root、alias指令用法和区别

    作者:Gakki root 与 alias 的定义 nginx 指定文件的路径有两种方式 root 和 alias...

  • Nginx核心配置分析

    1、虚拟主机配置 2、Nginx的日志配置 3、location的语法和匹配规则 4、alias与root的区别 ...

  • Nginx中root和alias的区别

    上面的配置浏览http://localhost/website/会显示404错误,因为root属性指定的值是要加入...

  • nginx中root和alias的区别

    alias是把location的值替换掉,而root是拼接上location的值。举个例子: 假设我们在服务器的路...

网友评论

      本文标题:Nginx中root与alias区别

      本文链接:https://www.haomeiwen.com/subject/lwnpgrtx.html