nginx 方向代理 通过变量代理多个服务

配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server {
     listen       80;
     server_name  xxxxxxxx;
     access_log    /var/log/nginx/inetrnal_access .log  main;
     proxy_set_header   Host             $host;
     proxy_set_header   X-Real-IP        $remote_addr;
     proxy_connect_timeout               60;
     proxy_read_timeout                  60;
     proxy_set_header   X-Forwarded-For $http_x_forwarded_for;
     #proxy_next_upstream                 error timeout http_500 http_502 http_503 http_504 http_404;
     add_header         X-Cache            "$upstream_cache_status from $server_addr" ;
     client_max_body_size 20m;
     location ~* ^/([A-Za-z0-9\-.]*)  {
     proxy_pass                      http: //fujie_ $1;
         }
 
         allow 10.0.0.0 /8 ;
         deny all;
  }
 
upstream fujie_ues-ws {
         sticky;
         server xxxxxxxx:8160 max_fails=3 fail_timeout=2;
         server xxxxxxxx:8160 max_fails=3 fail_timeout=2;
}
 
upstream fujie_mns-web {
         sticky;
         server xxxxxxxx:8156 max_fails=3 fail_timeout=2;
         server xxxxxxxx:8156 max_fails=3 fail_timeout=2;
}
 
upstream fujie_ufs {
         sticky;
         server xxxxxxxx:8090 max_fails=3 fail_timeout=2;
         server xxxxxxxx:8090 max_fails=3 fail_timeout=2;
}

location 那段的意思是,忽略大小写,路径匹配所有大小写字符和数字,以及横岗 后的任意一个字符,匹配任意数量

而方向代理的$1变量是location的路径的第一个参数,也就是正则匹配到的字符串
















本文转自wks9751CTO博客,原文链接: http://blog.51cto.com/wks97/2085573,如需转载请自行联系原作者




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值