[转] Nginx配置中的location、root、alias
Nginx配置中的location、root、alias
location & root
初始配置
[root@adailinux vhost]# cat rio.conf
server
{
listen 80;
server_name rio.com;
location /r/
{
root /data/wwwroot/rio.com/;
}
}
目录结构
[root@adailinux vhost]# tree /data/wwwroot/rio.com/
/data/wwwroot/rio.com/
├── file1.html
└── r
├── file2.html
└── t
└── file3.html
测试
更改配置
[root@adailinux vhost]# cat rio.conf
server
{
listen 80;
server_name rio.com;
location /r/
{
root /data/wwwroot/rio.com/t/;
}
} [root@adailinux vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@adailinux vhost]# /usr/local/nginx/sbin/nginx -s reload
测试:
总结
location和root组合相当于在root指定目录下进行location匹配,location所匹配内容必须保证在root指定目录的子目录,否则配置无效,而且location只能向下匹配,不能匹配location指定目录上一级目录中的内容。
location & alias
初始配置
[root@adailinux vhost]# cat rio.conf
server
{
listen 80;
server_name rio.com;
location /r/
{
alias /data/wwwroot/rio.com/r/;
}
}
测试
更改配置
[root@adailinux vhost]# cat rio.conf
server
{
listen 80;
server_name rio.com;
location /r/
{
alias /data/wwwroot/rio.com/;
}
} [root@adailinux vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@adailinux vhost]# /usr/local/nginx/sbin/nginx -s reload
测试
总结
location与alias组合,需要保证location匹配目录与alias指定目录级别相同,否则配置无效,与location和root组合相同的是,location所匹配内容也只能向下匹配。
注意事项
- 使用alias,目录名后面一定要加“/”
- alias只能在location中使用
补充:root&alias文件路径配置
root/alias 是指定文件路径的两种方式,主要区别就是怎么解析location后面的uri。 eg: 访问:http://localhost/appImg/abc.jpg
- root:
location ^~ /appImg/{
root /home/nginx;
}
这个location相当于访问服务器上的文件路径: /home/nginx/appImg/abc.jpg 。
- alias:
location ^~ /appImg/{
alias /home/nginx/;
}
这个location相当于访问服务器上的文件目录:/home/nginx/abc.jpg(即alias不会使用location后面配置的路径)。而且如果alias 指定的是目录,后面一定要加上 "/"。。。
(adsbygoogle = window.adsbygoogle || []).push({});
[转] Nginx配置中的location、root、alias的更多相关文章
- nginx配置中root与alias的区别
nginx指定文件路径有两种方式root和alias,这两者的用法区别,使用方法总结了下,方便大家在应用过程中,快速响应.root与alias主要区别在于nginx如何解释location后面的uri ...
- Nginx配置中一个不起眼字符"/"的巨大作用
文章转载自:https://mp.weixin.qq.com/s/QwsbuNIqLpxi_FhQ5pSV3w Nginx作为一个轻量级的,高性能的web服务软件,因其占有内存少,并发能力强的特点,而 ...
- nginx配置 location root alias
语法规则: location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...
- nginx配置文件中,location字段里面的root字段和别名alias
1. location里面的root例子 server{ listen ; server_name www.wzw.com; location /www { root /data/; //设置虚拟主机 ...
- nginx配置中root和alias的区别
例:访问http://127.0.0.1/download/*这个目录时候让他去/opt/app/code这个目录找. 方法一(使用root关键字): location / { root /usr/s ...
- nginx的location root alias指令以及区别
原文:http://blog.csdn.net/bjash/article/details/8596538 location /img/ { alias /var/www/image/; } #若按照 ...
- 【03】Nginx:location / root / alias
写在前面的话 前面我们谈了 nginx 基础的 WEB 服务配置以及定制我们的日志显示格式,接下来我能更加详细的说说 server 字段. location 字段 在 Server 中,如果我们只是一 ...
- Nginx一个server配置多个location(使用alias)
公司测试环境使用nginx部署多个前端项目.网上查到了两个办法: 在配置文件中增加多个location,每个location对应一个项目比如使用80端口,location / 访问官网: locati ...
- nginx配置文件中的location理解
关于一些对location认识的误区 1. location 的匹配顺序是"先匹配正则,再匹配普通". 矫正: location 的匹配顺序其实是"先匹配普通,再匹配正则 ...
随机推荐
- python3使用模块
Python内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env python3 # -*- codi ...
- 汇编指令之CMP, TEST指令
一.CMP指令 这一块呢,我不想上图了,汇编的博文我已经快要让我写吐了,其实也有好多我没有补充进来,比如进制,LEA指令,数据宽度,有符号,无符号的区分等等,但我真的要吐了,这些玩意我已经不是第一次写 ...
- Xml格式数据转map工具类
前言[ 最近在写一个业务,由于调UPS物流的接口返回的是一个xml格式的数据结果,我现在要拿到xml中某个节点的值,而这个xml数据是多节点多层级的,并且这某个节点的值有可能只有一条值,有可能有多条, ...
- python中优雅的杀死线程
上一篇博客中,杀死线程采用的方法是在线程中抛出异常 https://www.cnblogs.com/lucky-heng/p/11986091.html, 这种方法是强制杀死线程,但是如果线程中涉 ...
- liteos队列(五)
1. 概述 队列又称消息队列,是一种常用于任务间通信的数据结构,实现了接收来自任务或中断的不固定长度的消息,并根据不同的接口选择传递消息是否存放在自己空间.任务能够从队列里面读取消息,当队列中的消息是 ...
- Python从零开始——循环语句
一:Python循环语句知识概览 二:while循环 三:for遍历 四:循环控制
- [TCP/IP] SSL的通讯原理
SSL:位于传输层和应用层之间,专门实现在传输之前加密,在接收端给应用层之前解密;使用非对称加密技术 SSL原理 1.客户端与服务端建立连接 2.互相Hello(包含支持的版本.算法:加上随机数) 3 ...
- Linux 找文件
最简单的可以使用 find find . -name "libxxx.so" 还可以使用 locate libxxx.so
- flask中利用session实现用户记住密码
“记住密码”的实质,实际上就是把cookie的有效期设置的长一点,当用户没有选择记住密码时,cookie的有效期为会话结束,选择记住密码后,会根据服务器的设置延长cookie的有效期,默认是31天.在 ...
- LeetCode 112. Path Sum路径总和 (C++)
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...