root介绍

Syntax:	root path;
Default:
root html;
Context: http, server, location, if in location
Sets the root directory for requests. For example, with the following configuration

访问 http://localhost:80/i/top.gif,nginx匹配的文件路径是/data/w3/i/top.gif

location /i/ {
root /data/w3;
}

The /data/w3/i/top.gif file will be sent in response to the “/i/top.gif” request.

The path value can contain variables, except $document_root and $realpath_root.

A path to the file is constructed by merely adding a URI to the value of the root directive. If a URI has to be modified, the alias directive should be used.

alias介绍

Syntax:	alias path;
Default: —
Context: location
Defines a replacement for the specified location. For example, with the following configuration

访问http://localhost:80/i/top.gif,文件路径为/data/w3/images/top.gif

这里有个细节,nginx在解析root时会自动加上/,因此root可以省略斜杠,但alias路径结尾需要加上斜杠才能正确解析。

location /i/ {
alias /data/w3/images/;
}

on request of “/i/top.gif”, the file /data/w3/images/top.gif will be sent.

The path value can contain variables, except $document_root and $realpath_root.

If alias is used inside a location defined with a regular expression then such regular expression should contain captures and alias should refer to these captures (0.7.40), for example:

location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
alias /data/w3/images/$1;
}

When location matches the last part of the directive’s value:

location /images/ {
alias /data/w3/images/;
}

it is better to use the root directive instead:

location /images/ {
root /data/w3;
}

nginx的官方文档:

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

http://nginx.org/en/docs/http/ngx_http_core_module.html#root

nginx中的root和alias辨析的更多相关文章

  1. nginx中有关 root 和 alias的主要区别

    举个例子给伙伴们区别就明显看出来了,例子如下: location /img/ { alias /var/www/image/; }注意:如果按照上述配置的话,则访问/img/目录里面的文件时,ning ...

  2. Nginx中的root&alias文件路径及索引目录配置详解

    这篇文章主要介绍了Nginx中的root&alias文件路径及索引目录配置,顺带讲解了root和alias命令的用法,需要的朋友可以参考下     root&alias文件路径配置ng ...

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

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

  4. Nginx里的root/index/alias/proxy_pass的意思

    1.[alias] 别名配置,用于访问文件系统,在匹配到location配置的URL路径后,指向[alias]配置的路径.如: location /test/ { alias /home/sftp/i ...

  5. nginx 中 root和alias

    根本区别 一个请求的url= http://ip:port/path 在location中配置root和alias的区别: root是在location的正则之前拼接了路径 alias是在locati ...

  6. (转)Nginx静态服务配置---详解root和alias指令

    Nginx静态服务配置---详解root和alias指令 原文:https://www.jianshu.com/p/4be0d5882ec5 静态文件 Nginx以其高性能著称,常用与做前端反向代理服 ...

  7. Nginx静态服务配置---详解root和alias指令

    Nginx静态服务配置---详解root和alias指令 静态文件 Nginx以其高性能著称,常用与做前端反向代理服务器.同时nginx也是一个高性能的静态文件服务器.通常都会把应用的静态文件使用ng ...

  8. nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别

    1.多级目录配置 多级目录是指像/html/mypage 等等配置: server { listen 80; server_name localhost; location = /page1/ { # ...

  9. Nginx中root与alias的用法及区别:

    Nginx中root与alias都是定义location {}块中虚拟目录访问的文件位置: 先看看两者在用法上的区别: location /img/ { alias /var/www/image/; ...

随机推荐

  1. [ARC060D] 最良表現

    题目   点这里看题目. 分析   由于 KMP 的失配数组有着天然的找循环节的功能,因此我们不难想到对原串进行两次 KMP ,一正一反.   可以发现如下的规律:   1. 原串无循环节,这个时候 ...

  2. 分享一个我自己做的 Excel 万年历

    下载链接在此. 纯 Excel 公式实现,带农历,可自定义节日.配色. 带有紧凑日历和记事日历两种日历,均可直接 Ctrl+P 打印,且打印时不带有顶部的控制栏.

  3. 01---eclipse使用

    一.eclipse快捷键 1.alt+? 或 alt+/:自动补全代码或者提示代码,可用于main函数(main).输出函数(syso)等 2.ctrl+1:错误提示 3.ctrl+/:自动注释当前行 ...

  4. HTML中doctype的作用及几种类型详解

    一.DOCTYPE标签的定义与作用 <!DOCTYPE>是一个用于声明当前HTMl版本,用来告知web浏览器该文档使用是哪种 HTML 或者 XHTML 规范来解析页面,以便浏览器更加准确 ...

  5. tp6 路由匹配参数获取问题

    tp6是一个封装度很高的框架,在大部分场景下都能做到开箱即用 本次遇到情况为,当请求消息体为索引数组时,路由参数无法正常获取 首先看正常路由匹配 路由定义 Route::post('test/:a/: ...

  6. Linux性能优化思路

    性能测试的核心,就是找出性能瓶颈并进行性能优化,解决"慢"的问题,最终满足客户业务需求. [性能需求来源及性能问题现象] 性能需求的来源,主要分为以下几类: 项目组提出性能需求: ...

  7. 分享2个近期遇到的MySQL数据库的BUG案例

    近一个月处理历史数据问题时,居然连续遇到了2个MySQL BUG,分享给大家一下,也欢迎指正是否有问题. BUG1: 数据库版本:  MySQL5.7.25 - 28 操作系统: Centos 7.7 ...

  8. JavaWeb网上图书商城完整项目--验证码

    1.首先需要集成下面的jar 2.在web.xml配置验证码的servlet <?xml version="1.0" encoding="UTF-8"?& ...

  9. spring框架中JDK和CGLIB动态代理区别

    转载:https://blog.csdn.net/yhl_jxy/article/details/80635012 前言JDK动态代理实现原理(jdk8):https://blog.csdn.net/ ...

  10. Python3-sys模块-解释器相关参数与函数

    Python3中的sys模块提供了访问由解释器使用和维护的一些变量和与解释器强烈交互的函数 sys.argv 获取传递给Python脚本的参数列表,sys.argv[0]代表脚本本身,sys.argv ...