nginx中的root和alias辨析
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辨析的更多相关文章
- nginx中有关 root 和 alias的主要区别
举个例子给伙伴们区别就明显看出来了,例子如下: location /img/ { alias /var/www/image/; }注意:如果按照上述配置的话,则访问/img/目录里面的文件时,ning ...
- Nginx中的root&alias文件路径及索引目录配置详解
这篇文章主要介绍了Nginx中的root&alias文件路径及索引目录配置,顺带讲解了root和alias命令的用法,需要的朋友可以参考下 root&alias文件路径配置ng ...
- nginx location关于root、alias配置的区别
一.首先优先级如下: = 表示精确匹配,优先级最高 ^~ 表示uri以某个常规字符串开头,用于匹配url路径(而且不对url做编码处理,例如请求/static/20%/aa,可以被规则^~ /stat ...
- Nginx里的root/index/alias/proxy_pass的意思
1.[alias] 别名配置,用于访问文件系统,在匹配到location配置的URL路径后,指向[alias]配置的路径.如: location /test/ { alias /home/sftp/i ...
- nginx 中 root和alias
根本区别 一个请求的url= http://ip:port/path 在location中配置root和alias的区别: root是在location的正则之前拼接了路径 alias是在locati ...
- (转)Nginx静态服务配置---详解root和alias指令
Nginx静态服务配置---详解root和alias指令 原文:https://www.jianshu.com/p/4be0d5882ec5 静态文件 Nginx以其高性能著称,常用与做前端反向代理服 ...
- Nginx静态服务配置---详解root和alias指令
Nginx静态服务配置---详解root和alias指令 静态文件 Nginx以其高性能著称,常用与做前端反向代理服务器.同时nginx也是一个高性能的静态文件服务器.通常都会把应用的静态文件使用ng ...
- nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别
1.多级目录配置 多级目录是指像/html/mypage 等等配置: server { listen 80; server_name localhost; location = /page1/ { # ...
- Nginx中root与alias的用法及区别:
Nginx中root与alias都是定义location {}块中虚拟目录访问的文件位置: 先看看两者在用法上的区别: location /img/ { alias /var/www/image/; ...
随机推荐
- Go语言圣经[中文版]
近期整理了一篇Go语言圣经[中文版]在线版本,排版比较适合手机以及PC阅读. Go语言圣经[中文版本]
- ArrayList、LinkedList、Vector、Array和HashMap、HashTable
就 ArrayList 与 Vector 主要从二方面来说. 一.同步性:Vector 是线程安全的,也就是说是同步的,而ArrayList 是线程序不安全的,不是同步的 二.数据增长:当需要增长时, ...
- 解决Maven静态资源过滤问题
在项目的pom.xml中添加下面的内容 <build> <resources> <resource> <directory>src/main/java& ...
- python+selenium识别图片验证码
import timeimport pytesseractfrom PIL import Image, ImageEnhancefrom selenium import webdriver url = ...
- CSS优先级的两种理解方式
方式一:值相加 我们先去MDN看看官方的解释: 优先级是如何计算的? 优先级就是分配给指定的 CSS 声明的一个权重,它由 匹配的选择器中的 每一种选择器类型的 数值 决定. 而当优先级与多个 CSS ...
- (三)JavaMail发送附件
代码如下: package cases; import com.sun.mail.util.MailSSLSocketFactory; import javax.activation.DataHand ...
- visual studio 2005/2010/2013/2015/2017 vc++ c#代码编辑常用快捷键-代码编辑器的展开和折叠
visual studio 2005/2010/2013/2015/2017 vc++ c#代码编辑快捷键-代码编辑器的展开和折叠 VS2015代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代 ...
- Python在Linux下编译安装
[准备环境] Linux centos [前言] 1 linux下默认带Python,带的是2.7版本的 ,如果需要升级版本,需要把系统的自带的Python改名或者卸载,再次安装你所需要的Python ...
- WeChair项目Alpha冲刺(10/10)
团队项目进行情况 1.昨日进展 Alpha冲刺第十天 昨日进展: 前端:安排页面美化,设计实名认证 后端:更新dao层代码 数据库:修改数据表属性,与后端部署数据库交互 2.今日安排 前端:继续 ...
- Vuex怎么用(1)
1. vuex是什么 github站点: https://github.com/vuejs/vuex在线文档: https://vuex.vuejs.org/zh-cn/简单来说: 对应用中组件的状态 ...