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/; ...
随机推荐
- centos 7 c++连接mysql的常用函数说明及使用样例
以下函数使用之前需安装mysql,并包含mysql.h头文件,设置好mysqlclient动态库 一.mysql_init() MYSQL * mysql_init(MYSQL *mysql); // ...
- Linux系统如何设置开机自动运行脚本?
大家好,我是良许. 在工作中,我们经常有个需求,那就是在系统启动之后,自动启动某个脚本或服务.在 Windows 下,我们有很多方法可以设置开机启动,但在 Linux 系统下我们需要如何操作呢? Li ...
- Linux系统管理——Linux简介
UNIX与Linux发展史 UNIX发展历史 1.1965年,美国麻省理工学院(MIT),通用电气公司(GE)及AT&T的贝尔实验室联合开发Multics工程计划,其目标是开发一种交互式的具有 ...
- [AGC034F]RNG and XOR
题目 点这里看题目. 分析 第一步可以将\(A\)数组转化成概率\(P(j)\):每一步操作异或\(j\)的概率. 接着发现,\(x\)从\(0\)变成\(i\)的期望等于\(x\)从\( ...
- 第m大的身份证号码(局部排序代全局、结构体排序)
第m大的身份证号码(点击) 时间限制: 1 Sec 内存限制: 128 MB ...
- Oracle VM VirtualBox 连接 Centos7 minimal版
概述: 本博客是系列博客,主要讲述在Windows环境下安装虚拟机,在虚拟机中安装lunix系统,在lunix下安装docker,在docker中安装并使用常用的开发软件,比如tomcat.redis ...
- UDF_获取某年某月有多少天
UDF --获取某年某月有多少天 --drop function fn_GetDayofMonth_1 /* HLERP ( [dbo].[GetMonths] ) */ go create func ...
- 2019-02-05 Linux的一些常用命令学习2
黑马程序员python课的笔记 ls -l 显示文件详细信息 ls -l -h 以k形式显示大小 ls -a 显示指定目录下的所有子目录和文件,包括隐藏文件 ls匹配符 *代表任意个数的字符 ?代表任 ...
- C#数据结构与算法系列(六):链表——双链表(Double-LinkedList)
1.对比单向链表 单向链表查找的方向只能是一个方向,而双向链表可以向前或者向后查找 单向链表不能自我删除,需要靠辅助节点,而双向链表可以自我删除 对于单向链表的删除,我们首先要找到单向链表待删除节点的 ...
- Python删除一个列表元素的方法
参考资料: https://www.cnblogs.com/xiaodai0/p/10564956.html https://www.cnblogs.com/huangbiquan/articles/ ...