(5) nginx:location
location 语法
location 有”定位”的意思, 根据Uri来进行不同的定位.
在虚拟主机的配置中,是必不可少的,location可以把网站的不同部分,定位到不同的处理方式上.
比如, 碰到.php, 如何调用PHP解释器? --这时就需要location
location 的语法
location [=|~|~*|^~] patt {
}
中括号可以不写任何参数,此时称为一般匹配
也可以写参数
因此,大类型可以分为3种
location = patt {} [精准匹配]
location patt{} [一般匹配]
location ~ patt{} [正则匹配]
如何发挥作用?:
首先看有没有精准匹配,如果有,则停止匹配过程.
location = patt {
config A
}
如果 $uri ==patt,匹配成功,使用configA
location = / {
root /var/www/html/;
index index.htm index.html;
}
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
如果访问 http://xxx.com/
定位流程是
1: 精准匹配中 ”/” ,得到index页为 index.htm
2: 再次访问 /index.htm , 此次内部转跳uri已经是”/index.htm” ,
根目录为/usr/local/nginx/html
3: 最终结果,访问了/usr/local/nginx/html/index.htm
再来看,正则也来参与.
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
location ~ image {
root /var/www/image;
index index.html;
}
如果我们访问 http://xx.com/image/logo.png
此时, “/” 与”/image/logo.png”匹配
同时,”image”正则 与”image/logo.png”也能匹配,谁发挥作用?
正则表达式的成果将会使用.
图片真正会访问 /var/www/image/logo.png
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
location /foo {
root /var/www/html;
index index.html;
}
我们访问http://xxx.com/foo
对于uri “/foo”, 两个location的patt,都能匹配他们
即 ‘/’能从左前缀匹配 ‘/foo’, ‘/foo’也能左前缀匹配’/foo’,
此时, 真正访问 /var/www/html/index.html
原因:’/foo’匹配的更长,因此使用之.;
(5) nginx:location相关推荐
- nginx location配置 - ttlsa教程系列之nginx
为什么80%的码农都做不了架构师?>>> 今天讲下location的用法,部分内容是直接从网络上摘取的,这边做了一个整理,为了便于理解和学习,我这边做了一些例子. 语法规则: ...
- 关于Nginx location中配置proxy_pass转发时斜线'/'导致的404问题
2019独角兽企业重金招聘Python工程师标准>>> 在Nginx location通用匹配规则中配置proxy_pass转发时,假设有如下location配置: location ...
- php localtion,详解Nginx Location配置
今天有一位同学问到 Nginx 的站点多路径匹配的问题? 1.www.domain.com/a 需要返回 /var/www/domain.com/a/index.html 2.www.domain.c ...
- Nginx location执行顺序和匹配规则
nginx location执行顺序和匹配原则根据location的特点分为普通和正则两种,执行顺序和匹配规则的差异也在于此. 执行顺序 nginx会优先执行普通location,不管普通locati ...
- nginx location 匹配 多个规则_三道小练习助你弄懂 Nginx location 匹配
在 Nginx 中我们可以通过配置 location 指令块,来决定一个请求 url 如何处理.如果我们编写了多条 location 指令块,如何保证各个 location 不会产生冲突?如何理清 l ...
- Nginx location(正则)
Nginx location(正则) 1.nginx location 2.匹配标识说明 3.不同uri及特殊字符组合匹配的顺序说明 4.示例 1.nginx location location 指令 ...
- location ~ .php$,nginx location指令详解,
nginx location指令详解, location匹配的是nginx的哪个变量? $request_uri location的匹配种类有哪些? =开头表示精确匹配 ^~ 开头,注意这不是一个正则 ...
- Nginx——location配置
1.基本语法 location [=|~|~*|^~|@] pattern {--} 其中,[=|~|~*|^~|@]被称作location modifier,这会定义Nginx如何去匹配其后的pat ...
- nginx location 配置详细解释
语法规则: location [=|~|~*|^~] /uri/ { - } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...
- 有关nginx location规则
由于公司最近在做nginx相关项目,研究了一下location的规则,主要参考的博文为http://www.jb51.net/article/47761.htm 的文章,但是自己实际操作一下后,发现了 ...
最新文章
- ROS之py文件权限
- pandas读写MySQL数据库详解及实战
- 前端二十九:两个盒子居中的练习
- javascript js jquery获取元素位置代码总结
- H3C——路由策略和策略路由实例配置
- android intent传对象,startActivityForResult使用, setResult(RESULT_OK)使用,getArguments(),
- android日历长按拖拽,CalendarView
- Git常见问题及报错
- .gitignore和“以下未跟踪的工作树文件将被签出覆盖”
- LINUX移植——LED驱动移植
- android iphone字体,ios字体适配的三种实现方法
- clover更新驱动 后不能开机_Big Sur安装常见问题【持续更新】
- 智能家居APP的竞品分析报告(米家)
- 野火指南者ESP8266模块学习
- STM32 触摸屏触摸功能
- wtg linux双系统,说走就走的WTG系统 国民好物aigo固态硬盘让你随时随地双系统
- 暗影精灵双系统(win10和Ubuntu16.04)安装+Cuda和tensorflow安装-深度学习环境配置
- 如何查询SCI和EI索引号
- 浅谈仪器控制【1.Python与Labview/Labwindows】
- 【信号与系统】(二十)傅里叶变换与频域分析——取样定理
热门文章
- JVM系列之:JIT中的Virtual Call
- java中三种常见内存溢出错误的处理方法
- ActiveMQ的Transport Connectors配置(六)
- Leecode05. 最长回文子串——Leecode大厂热题100道系列
- 为什么你的引用字体颜色那么淡? CSDN排版、图片尺寸、字体颜色、字体等
- [leetcode] 5.最长回文子串
- python三级字典_python_三级字典
- 普通平键的主要尺寸有_艾创米:解密指纹锁锁体尺寸测量方法
- hyperion高光谱参数_收藏!光纤光谱仪在激光领域的典型应用
- linux结束进程_生人勿近之Linux里养僵尸