Nginx 配置 Location 规则优先级问题
nginx 的 location与配置中 location 顺序没有关系,与 location 表达式的类型有关。相同类型的表达式,字符串长的会优先匹配。
以下是按优先级排列说明:
- 等号类型(=)的优先级最高。一旦匹配成功,则不再查找其他匹配项。
- ^~类型表达式。一旦匹配成功,则不再查找其他匹配项。
- 正则表达式类型(~ ~*)的优先级次之。如果有多个location的正则能匹配的话,则使用正则表达式最长的那个。
- 常规字符串匹配类型。按前缀匹配。
location ^~ /static/ {
# 匹配任何以 /static/ 开头的地址,一旦匹配成功,则不再查找其他匹配项。
root /opt/web/;
}
location /static/ {
# 匹配任何以 /static/ 开头的地址,匹配符合以后,还要继续往下搜索
}
我的环境是有一个 spring boot 的项目,默认使用jar包运行,静态资源由 spring 配置的路由管理,现在只要加一个静态服务器(服务器需要存在 static 目录,或者 配置两个 server 使用不同的域名)server {
listen 80;
server_name web.xxx.com;
location ^~ /static/ {
root /opt/web/;
}
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
}
#静态页面
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /opt/web/;
expires 1d;
}
REFER:
https://www.cnblogs.com/linjiqin/p/5532119.html
http://blog.csdn.net/xy2204/article/details/47749405
Nginx 配置 Location 规则优先级问题的更多相关文章
- rewrite规则写法及nginx配置location总结
rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用. 例如http://seanlook.com/a/we/index.php ...
- Nginx配置location及rewrite规则
Nginx配置location及rewrite规则 示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } loca ...
- nginx配置location总结及rewrite规则写法【转】
转自 nginx配置location总结及rewrite规则写法 | Sean's Noteshttp://seanlook.com/2015/05/17/nginx-location-rewrite ...
- Nginx配置location总结及rewrite规则写法
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 32.0px "Helvetica Neue"; color: #323333 } p. ...
- nginx配置location总结及rewrite规则写法(转)
一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的地址都以 / 开头,所以这 ...
- nginx配置location总结及rewrite规则写法 (若配置reload或restart不生效就stop start)
location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的 ...
- nginx配置 location及rewrite规则详解
1. location正则写法 语法规则: location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url ...
- nigx配置location规则
以下是收集的,对于不是很熟的朋友,配置转发很有帮助 1.location匹配命令和优先级: 优先级: Directives with the = prefix that match the query ...
- Nginx 配置 location 以及 return、rewrite 和 try_files 指令
正则表达式 Nginx 内置的全局变量 location 前缀字符串及优先级 示例 location 匹配原则 if 和 break 指令 if break return.rewrite 和 try_ ...
随机推荐
- weat!!团队
摘要: 团队名称:weat!! 团队成员:刘波 崔和杰 简介: 刘波:性别男,爱好:动漫,徒步旅行.在组内负责程序编写这一部分. 优点:认真负责,不懂就会去问. 崔和杰:性别男,爱好:篮球.在组内负责 ...
- Forward团队-爬虫豆瓣top250项目-团队编程项目开发环境搭建过程
本次结对编程和团队项目我都需要用python环境,所以环境的搭建是一样的.(本文部分内容引用自己博客:http://www.cnblogs.com/xingyunqi/p/7527411.html) ...
- Hdu4687 Boke and Tsukkomi
Boke and Tsukkomi Time ...
- hdu 4902 线段树+逆向模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4902 出n个数,然后对这n个数进行两种操作: 如果是 1 l r x,则把 [l, r] 区间里面的每一个数都变 ...
- hdu 4455 Substrings(计数)
题目链接:hdu 4455 Substrings 题目大意:给出n,然后是n个数a[1] ~ a[n], 然后是q次询问,每次询问给出w, 将数列a[i]分成若干个连续且元素数量为w的集合,计算每个集 ...
- 广搜 poj3278 poj1426 poj3126
Catch That Cow Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Ja ...
- Oracle EBS登陆后,直接打开某个特定Form/Page
http://blog.csdn.net/pan_tian/article/details/8169339 有一个小技巧,Oracle EBS登陆后可以绕过职责和功能的选择过程,就可以直接打开某个特定 ...
- node-webkit学习(3)Native UI API概览
node-webkit学习(3)Native UI API概览 文/玄魂 目录 node-webkit学习(3)Native UI API概览 前言 3.1 Native UI api概览 Exte ...
- 通过 sysprocesses 简单查询死锁及解决死锁办法
简单查询死锁,如下四步可以轻松解决: 第一步:查询死锁语句 1: 条件是 blocked <> 0 select dbid,* from sys.sysprocesseswhere 1=1 ...
- Button去除边框方法
<Button Content="Button" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey} ...