Nginx location&rewrite - ≮零℃空间≯ - 51CTO技术博客
来源:百度文库 编辑:神马文学网 时间:2024/05/24 02:37:43
Nginx的Location可以有以下几个匹配:
1. = 严格匹配这个查询。如果找到,停止搜索。
2. ^~ 匹配路径的前缀,如果找到,停止搜索。
3. ~ 为区分大小写的正则匹配
4. ~* 为不区分大小写匹配
例子:
location = / {
# matches the query / only.
# 只匹配 / 查询。
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
# 匹配任何查询,因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配。
[ configuration B ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
[ configuration C ]
}
location ~* ".(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration C.
# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。然而所有 /images/ 目录的请求将使用 Configuration C。
[ configuration D ]
}
Rewrite指令
rewrite regex replacement flag
后面的flag可以是:
last - completes processing of rewrite directives, after which searches for corresponding URI and location
break - completes processing of rewrite directives
redirect - returns temporary redirect with code 302; it is used if the substituting line begins with http://
permanent - returns permanent redirect with code 301
需要注意的是,如果rewrite后,不要它再去匹配其它的location,则需要加上break,如:
location ^~ /html/l/
{
root /opt/docparser;
rewrite "^/html/l/(.*)$" /$1;
#注意,需要有break,否则rewrite后还会继续匹配下面的location
break;
}
location ~ /(.*)$ {
proxy_pass http://127.0.0.1:8080;
}
本文出自 51CTO.COM技术博客
1. = 严格匹配这个查询。如果找到,停止搜索。
2. ^~ 匹配路径的前缀,如果找到,停止搜索。
3. ~ 为区分大小写的正则匹配
4. ~* 为不区分大小写匹配
例子:
location = / {
# matches the query / only.
# 只匹配 / 查询。
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
# 匹配任何查询,因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配。
[ configuration B ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
[ configuration C ]
}
location ~* ".(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration C.
# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。然而所有 /images/ 目录的请求将使用 Configuration C。
[ configuration D ]
}
Rewrite指令
rewrite regex replacement flag
后面的flag可以是:
last - completes processing of rewrite directives, after which searches for corresponding URI and location
break - completes processing of rewrite directives
redirect - returns temporary redirect with code 302; it is used if the substituting line begins with http://
permanent - returns permanent redirect with code 301
需要注意的是,如果rewrite后,不要它再去匹配其它的location,则需要加上break,如:
location ^~ /html/l/
{
root /opt/docparser;
rewrite "^/html/l/(.*)$" /$1;
#注意,需要有break,否则rewrite后还会继续匹配下面的location
break;
}
location ~ /(.*)$ {
proxy_pass http://127.0.0.1:8080;
}
本文出自 51CTO.COM技术博客
Nginx location&rewrite - ≮零℃空间≯ - 51CTO技术博客
零成本解决电脑升级问题 - happy ending - 51CTO技术博客-领先的IT技...
在linux上增加swap交换空间 - ctodream - 51CTO技术博客
linux下监控磁盘使用空间的脚本 - firsthoo - 51CTO技术博客
堆叠 - 漫步云端 - 51CTO技术博客
人生三字经 - 紫轩阁 - 51CTO技术博客
CTime::Format - 狼窝 - 51CTO技术博客
OpenNMS系统架构 - 技术改变人生 - 51CTO技术博客
中型企业网络构建案例 - 张选波博客 - 51CTO技术博客
UML序列图详解(1) - 笨笨城 - 51CTO技术博客
小结主要排序算法 - 子 孑 - 51CTO技术博客
VISTA系统下装AUTOCAD 2006 - Alexa - 51CTO技术博客
软件语言与应用领域 - huawen - 51CTO技术博客
讨人喜欢的27个原则 - 雨荷 - 51CTO技术博客
netstat参数 - 独意 - 51CTO技术博客
VRRP与HSRP的区别 - SENSE - 51CTO技术博客
RouterOS 基础应用教程 - Pizzn - 51CTO技术博客
vim全局替换命令 - 建四狼 - 51CTO技术博客
Windows 2003 DNS配置攻略 - lgzeng - 51CTO技术博客
zz MPLS认识一 - 911255 - 51CTO技术博客
ARP原理 - 小小菜鸟 - 51CTO技术博客
regsvr32 注册.dll的用法 - carywu - 51CTO技术博客
IT运维管理困境 - 51CTO技术博客
IE7自动完成口令获取 - 暖月无痕 - 51CTO技术博客