nginx location rewrite 优先级问题

chongzai 发布于 2011/11/14 16:32
阅读 2K+
收藏 0

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

目的: www.test.com/abcd   跳转到  www.test.com/search/searchWd.do?wd=abcd

abcd 要符合正则 [0-9A-Za-z]{4,30}

location ~ ^/[0-9A-Za-z]{4,30}$/ {

rewrite "^/(.+)$" http://test.com/ search/searchWd.do?wd=$1 last;

}

 

        location / {

#if ($uri ~ "^/[0-9]{1,30}$") {

#rewrite "^/(.+)$" http://test.com/ search/searchWd.do?wd=$1 last;

#}

proxy_pass http://test.com;

}

目前情况:运行下面一个location

小弟菜鸟,学习中………………请各位指教

 

以下是问题补充:

@chongzai:www.test.com/abcd 这个为什么总是匹配/ 是我的正则错了.请各位指正一下 (2011/11/14 18:10)
@chongzai:求 nginx 资料,文档或者书. (2011/11/14 18:11)
加载中
0
红薯
红薯
location 是按顺序进行匹配的,匹配到谁就是谁了
0
用户名已存在
用户名已存在

nginx first searches for the most specific location given by literal strings regardless of the listed order.

/ 是最低的优先级

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部