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. 修改主机名和修改主机映射和ssh免登陆

    1.修改主机名 vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=cc3 2.修改主机映射 vi /etc/hosts 127.0.0.1 loca ...

  2. Python29之字符str与字节bytes

    详解见这位大神:https://www.cnblogs.com/xiaobingqianrui/p/9870480.html 实际上字符串和字节之间的转换过程,就是编码解码的过程,我们必须显示的指定编 ...

  3. PB笔记之数据窗口大小自适应的方式

    1.在OPEN 事件中设置数据窗口大小属性 tab_1.tabpage_6.dw_6.x=0tab_1.tabpage_6.dw_6.y=0tab_1.tabpage_6.dw_6.width=thi ...

  4. 微信小程序使用 iconfont

    小程序中使用 iconfont 在 iconfont.cn 中下载图标库, 直接将其中的 iconfont.css 复制到小程序目录中,并将扩展名改为 wxss: 在使用时在对应的样式文件 wxss ...

  5. java实现HTTP请求 HttpUtil

    示例: package com.sensor.utils; import java.net.HttpURLConnection; import java.net.URL; public class H ...

  6. jmeter保存返回数据到csv

    添加一个线程组,然后右键选择“正则表达式提取器” 配置正则表达式: 添加添加后置处理器beanshell postprocessor: 保存提取的数据: 代码: FileWriter fstream ...

  7. 使用其他身份运行计算机(DOS命令)

    runas/user:administrator cmd d: cd esop sfispri.ini

  8. BeautifulSoup库的安装与使用

    BeautifulSoup库的安装 Win平台:“以管理员身份运行” cmd 执行 pip install beautifulsoup4 演示HTML页面地址:http://python123.io/ ...

  9. Python-pptx库的运用

    Win32com该库需要调用Microsoft PowerPoint,我将重新安装计算机Win 10,简单安装了pycharm的最新版本,然后发现创建的项目与之前的创建的项目结构不同.还有更多这样的事 ...

  10. dvaJS Model之间的调用

    const Model: ModelType = { namespace: 'namesps', state: { data: {} }, effects: { *fetch({ payload, c ...