现在需求如下:

nginx上配有aaa.example.com的虚拟主机,现在需要将访问http://aaa.example.com/api/x.x/client/的请求转到http://bbb.example.com/api/x.x/client/,bbb.example.com的虚拟主机在另外一台nginx上,其中x.x表示位数不定的版本号,如:1.0或1.20.345都可能。请求转过去要求url保持不变

server {
listen 80;
server_name localhost;    localhost为192.168.223.136

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm index.php;
}
location ^~/api/ {
root html;
rewrite ^/api/([0-9]+\.[0-9]+)/client/(.*)$ http://192.168.223.137/api/$1/client/$2 redirect;
}

location ^~/api/ {
root html;
index index.html;
rewrite ^/api/([0-9]+\.[0-9]+)/client/(.*)$ http://192.168.223.137/api/$1/client/$2 redirect;
}
第一个小括号匹配的为$1
第二个小括号匹配的为$2
 

然后测试匹配结果:

此篇博文持续更新。。。。

http://www.linuxidc.com/Linux/2014-01/95493.htm

nginx之rewrite匹配需求的更多相关文章

  1. Nginx的Rewrite正则表达式,匹配非某单词

    Nginx的Rewrite正则表达式,匹配非某单词 由于要rewrite一个地址从 /mag/xx/xxx/ -> /m/xxx 但原先 /mag/xx/more/ 要保留 这就得写一个比较奇特 ...

  2. Nginx中location匹配及rewrite重写

    目录 一.常用的Nginx正则表达式 二.location 2.1.location三类匹配类型 2.2.常用的匹配规则 2.3.location优先级 2.3.1.举例说明 2.4.实际网站使用中, ...

  3. nginx 带? rewrite 规则

    由于需要重定向 url ,nginx需要rewrite .参考文献 http://huangqiqing123.iteye.com/blog/2083434 需求:将http://10.106.1.3 ...

  4. Nginx的rewrite应用

    Rewrite主要的功能是实现URL重写,Nginx 的 Rewrite 规则采用 PCRE Perl 兼容正则表达式的语法进行规则匹配,如相使用 Nginx 的 Rewrite 功能,在编译 Ngi ...

  5. nginx location 正则匹配

    nginx 统计语句1.根据访问IP统计UV awk '{print $1}' access.log|sort | uniq -c |wc -l2.统计访问URL统计PV awk '{print $7 ...

  6. 04 . Nginx的Rewrite重写

    Rewrite简介 # Rewrite对应URL Rewrite,即URL重写,就是把传入web的请求重定向到其他URL的过程. # 当运维遇到要重写情况时,往往是要程序员把重写规则写好后,发给你,你 ...

  7. Nginx中rewrite实现二级域名、三级域名、泛域名、路径的重写

    最常见的: 静态地址重定向到带参数的动态地址 rewrite "^(.*)/service/(.*)\.html$" $1/service.php?sid=$2 permanent ...

  8. nginx 配置rewrite 笔记

    nginx 配置rewrite笔记: 通过下面的示例来说明一下,1. 先说说location : location 表示匹配传入的url地址,其中配置符有多种,各种情况的意义不一样: location ...

  9. Nginx之location 匹配规则详解

    有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...

随机推荐

  1. PHP获取当前日期和时间格式化方法

    使用函式 date() 实现 <?php echo $showtime=date("Y-m-d H:i:s");?> 显示的格式: 年-月-日 小时:分钟:妙 相关时间 ...

  2. Angular2+学习第1篇 简介

    历史: Angular是Google推出的Web前端开发框架,从12年发布起就受到了强烈的关注,他首次提出了双向绑定的概念,让人耳目一新. Angular 2特性 就在2016年9月中旬,时隔4年,G ...

  3. HDU_5527_Too Rich

    Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. 解决64位debian下无法安装ia32库的问题

    原文地址:http://crunchbang.org/forums/viewtopic.php?pid=277918 因为64位debian源中并没有包括32位的软件包,所提安装ia32会提示依赖无法 ...

  5. mybatis调用oracle存储过程例子.

    1.MYBATIS方法: <select id="getFlowNum" statementType="CALLABLE"> <![CDATA ...

  6. C. Mail Stamps---cf29c(离散化,图)

    题目链接:http://codeforces.com/problemset/problem/29/C 题意就是有n(1e5)个点,找到一条能把所有的点都包含在内的路径,由于点的编号是 1e9 所以不得 ...

  7. Linux 下线程的理解

    2017-04-03 最近深入研究了下Linux线程的问题,发现自己之前一直有些许误解,特记之…… 关于Linux下的线程,各种介绍Linux的书籍都没有深入去解释的,或许真的如书上所述,Linux本 ...

  8. 基于Maven的SSM框架搭建

    Maven + Spring + Spring MVC + Mybatis + MySQL整合SSM框架 1.数据库准备 本文主要想实现SSM框架的搭建,并基于该框架实现简单的登录功能,那么先新建一张 ...

  9. 为什么使用Sails?

    http://sailsdoc.swift.ren/ 这里有 sails中文文档 http://www.jianshu.com/p/ac2da4142259 前言 入手Node.js半年,从用Expr ...

  10. CanvasRenderingContext2D.imageSmoothingEnabled

    https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled 这是一个 ...