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. 《Mysql - 幻读》

    一:准备 - 为了深入了解幻读,准备数据. CREATE TABLE `t` ( `id` ) NOT NULL, `c` ) DEFAULT NULL, `d` ) DEFAULT NULL, PR ...

  2. c语言实现串

    串  (string)是由零个或者多个字符组成的有限序列,又称字符串 一般表示为 S=“ a1 a2 a3 a4  . . . . . an”    其中S 是串名,双引号串起来的是串值,(有些书用单 ...

  3. Hadoop 完全分布式搭建

    搭建环境 https://www.cnblogs.com/YuanWeiBlogger/p/11456623.html 修改主机名------------------- 1./etc/hostname ...

  4. 在uboot里面添加环境变量使用run来执行

    在uboot里面添加环境变量使用run来执行 本文链接:https://blog.csdn.net/u010979030/article/details/41038259 Author:杨正  Dat ...

  5. 简介:google ctemplate:简单易用的文字模板(转载)

    转自:http://blog.csdn.net/aladdina/article/details/4531736 CTemplate 是一个简单实用.功能强大的文字模板(template langua ...

  6. eigenface算法笔记

    昨天看了PCA(PCA算法介绍见上一篇),今天继续看eigenface,在这里把eigenface的过程梳理下: EigenFace本质上讲,是把人脸从像素空间变换到另一个空间,在另一个空间中做相似性 ...

  7. R_数据操作_初级_03

    数据的输入:详见(http://cran.r-project.org/doc/manuals/R-data.pdf下载的R Data Import/Export手册②) 1.键盘输入:使用edit() ...

  8. 【MySQL】数据库(分库分表)中间件对比

    分区:对业务透明,分区只不过把存放数据的文件分成了许多小块,例如mysql中的一张表对应三个文件.MYD,MYI,frm. 根据一定的规则把数据文件(MYD)和索引文件(MYI)进行了分割,分区后的表 ...

  9. Topics in CS(difference between compile and interpret)

    编译 Compile:把整个程序源代码翻译成另外一种代码,然后等待被执行,发生在运行之前,产物是「另一份代码」. 解释 Interpret:把程序源代码一行一行的读懂然后执行,发生在运行时,产物是「运 ...

  10. SVM-支持向量机总结

    一.SVM简介 (一)Support Vector Machine 支持向量机(SVM:Support Vector Machine)是机器学习中常见的一种分类算法. 线性分类器,也可以叫做感知机,其 ...