nginx location中root指令和alias指令

功能:将url映射为文件路径,以返回静态文件内容

差别:root会将完整的url映射进文件路径中

alias只会将location后的url映射到文件路径中

location   /root {

root    html;

}

当访问为http://192.168.25.35/root/hello.html时

会将url --> root/hello.html拼接在root指令的值html下

即会在路径html/root/html/hello.html下找资源,如果找到则返回资源内容

如果找不到则返回404错误

再如

访问http://192.168.25.35/a/b/c.html

"/usr/local/nginx/html/a/b/c.html" failed (2: No such file or directory)

location /alias {

alias   html;

index  index.html index.htm;

}

当访问http://192.168.25.35/alias/a/hello.html时

会将location后的url---> a/hello.html(注意不包括location后 /alias 路径)拼接在

alias指令值html后,即html/a/hello.html下找资源

再如

http://192.168.25.35/alias/location/index/

"/usr/local/nginx/html/location/index/index.html" is not found (2: No such file or directory)

http://192.168.25.35/alias/location/index

"/usr/local/nginx/html/location/index" failed (2: No such file or directory)

通过以上报错信息得知,url后有/时,会默认找index.html资源

当url访问目录并以 / 结尾,则nginx默认会返回index指令配的文件内容

当index指定一个不存在的文件,autoindex on时,url访问目录并以 / 结尾时,返回文件目录

location /alias {
  alias html;
  index a.html;
  autoindex on;
}

当访问http://192.168.25.35/alias/时,将返回html下的文件目录结构

nginx location中root指令和alias指令的区别的更多相关文章

  1. nginx 的 content阶段的root指令与alias指令

    root 与alias指令 Syntax: alias path; Default: — Context: location Syntax: root path; Default: root html ...

  2. 你真的了解nginx重定向URI?-rewrite和alias指令

    未经允许不得转载!最近发现有博主转载我的文章,并没有跟我打招呼,也没有注明出处!!!! 熟悉Nginx的同学都知道Nginx可以用来做负载均衡和反向代理,非常好用.做前后端分离也是非常的方便. 今天我 ...

  3. nginx配置中root与alias的区别

    nginx指定文件路径有两种方式root和alias,这两者的用法区别,使用方法总结了下,方便大家在应用过程中,快速响应.root与alias主要区别在于nginx如何解释location后面的uri ...

  4. nginx配置中root和alias的区别

    例:访问http://127.0.0.1/download/*这个目录时候让他去/opt/app/code这个目录找. 方法一(使用root关键字): location / { root /usr/s ...

  5. nginx location关于root、alias配置的区别

    一.首先优先级如下: = 表示精确匹配,优先级最高 ^~ 表示uri以某个常规字符串开头,用于匹配url路径(而且不对url做编码处理,例如请求/static/20%/aa,可以被规则^~ /stat ...

  6. Nginx Location模块

    相关知识点:URI:统一资源标识符,是一个用于标识某一互联网资源名称的字符串,该种标识允许用户对任何的资源通过特定的协议进行交互操作.URL:统一资源定位符,由三部分组成(1)http://协议 (2 ...

  7. Nginx Location规则

    Nginx由内核和模块组成,其中内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端的请求映射到一个location block,而location是Nginx配置中的一个指令 ...

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

    nginx指定文件路径有两种方式root和alias,指令的使用方法和作用域: [root] 语法:root path 默认值:root html 配置段:http.server.location.i ...

  9. nginx的location root alias指令以及区别

    原文:http://blog.csdn.net/bjash/article/details/8596538 location /img/ { alias /var/www/image/; } #若按照 ...

随机推荐

  1. LeetCode 145. 二叉树的后序遍历(Binary Tree Postorder Traversal)

    145. 二叉树的后序遍历 145. Binary Tree Postorder Traversal 题目描述 给定一个二叉树,返回它的 后序 遍历. LeetCode145. Binary Tree ...

  2. log4j向指定文件输出日志

    一.log4j.properties中的配置 log4j.logger.cache=INFO,ERROR,batchFile log4j.addivity.batchFile=false log4j. ...

  3. 剑指offer64:滑动窗口的最大值

    1 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4 ...

  4. docker 实践八:docker-compose

    本篇介绍 docker 官方三剑客之一的 docker-compose. 注:环境为 CentOS7,docker 19.03. docker-compose docker-compose 的前身是开 ...

  5. PB自动换行

    1.在DataWindow Painter中打开DataWindow; 2.在需设定自动折行的列上单击, 查看右侧的属性窗口: 3.点击Position标签, 选中Autosize Height 多选 ...

  6. 括号匹配问题 —— Deque双端队列解法

    题目: 给定一个只包括 '(',')','{','}','[',']'?的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合.注意空字符串可 ...

  7. springboot 的启动流程

    1.我们springboot 项目的启动类如下. 方式1 @SpringBootApplicationpublic class SpringbootZkLockApplication { public ...

  8. 常用算法之排序(Java)

    一.常用算法(Java实现) 1.选择排序(初级算法) 原理:有N个数据则外循环就遍历N次并进行N次交换.内循环实现将外循环当前的索引i元素与索引大于i的所有元素进行比较找到最小元素索引,然后外循环进 ...

  9. 微信小程序自定义组件——接受外部传入的样式类

    https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html 外部样式类 有时, ...

  10. Ubuntu安装opencv3.4.4教程

    1 去官网下载opencv 在本教程中选用的是opencv3.4.4,下载链接 http://opencv.org/releases.html ,选择sources. 2 解压 unzip openc ...