首页 > 其他 > 详细

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

时间:2018-03-12 16:46:11      阅读:186      评论:0      收藏:0      [点我收藏+]
配置如下

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的路径的第一个参数,也就是正则匹配到的字符串

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

原文:http://blog.51cto.com/wks97/2085573

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!