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 102. 二叉树的层次遍历(Binary Tree Level Order Traversal) 8

    102. 二叉树的层次遍历 102. Binary Tree Level Order Traversal 题目描述 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 每 ...

  2. 用pytorch1.0快速搭建简单的神经网络

    用pytorch1.0搭建简单的神经网络 import torch import torch.nn.functional as F # 包含激励函数 # 建立神经网络 # 先定义所有的层属性(__in ...

  3. ABP中的本地化处理(下)

    在上篇文章中我们的重点是讲述怎样通过在Domain层通过PreInitialize()配置ILocalizationConfiguration中的Sources(IList<ILocalizat ...

  4. Markdown 语法 (转载)

    Markdown 语法整理大集合2017   1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // ...

  5. pandas之时间序列笔记

    时间戳tiimestamp:固定的时刻->pd.Timestamp 固定时期period:比如2016年3月份,再如2015年销售额->pd.Period 时间间隔interval:由起始 ...

  6. PowerBuilder学习笔记之行删除卡死问题

    在数据窗口勾选这两个选项后,在删除行数据时会导致系统直接崩溃退出

  7. [Luogu5320][BJOI2019]堪破神机(DP+斯特林数)

    https://www.cnblogs.com/cjyyb/p/10747543.html 特征方程+斯特林反演化简式子,要注意在模998244353意义下5没有二次剩余,所以每个数都要用$a+b\s ...

  8. git 如何取消add操作

    可以直接使用命令    git reset HEAD 这个是整体回到上次一次操作 绿字变红字(撤销add) 如果是某个文件回滚到上一次操作:  git reset HEAD  文件名 红字变无 (撤销 ...

  9. C# 微信消息模板 发送

    项目要用到微信提醒 ,加上调转到小程序页面,或者 指定url 用到  RestSharp.Senparc.Weixin 类库 一开始直接照着微信示例直接post进去 发现一直提示 47001  ,估计 ...

  10. Go 互斥锁(sync.Mutex)和 读写锁(sync.RWMutex)

    什么时候需要用到锁? 当程序中就一个线程的时候,是不需要加锁的,但是通常实际的代码不会只是单线程,所以这个时候就需要用到锁了,那么关于锁的使用场景主要涉及到哪些呢? 多个线程在读相同的数据时 多个线程 ...