【nginx】简易接口转发实现

    set $name_ver "${http_app_name}_${http_app_ver}";
    if ($name_ver = "xcx_110") {
        rewrite (.*) /REJUMP/$1 break;
    }

    location /REJUMP{
        rewrite ^/REJUMP/(.*) $1 break;
        internal;
        proxy_pass         http://192.168.1.10;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_connect_timeout 20;
        proxy_send_timeout 30;
        proxy_read_timeout 30;
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
    }

    #location ~ .*\.(php|php5)?$
    #{
    #    fastcgi_pass  php56;
    #    fastcgi_index index.php;
    #    include fcgi.conf;
    #}

    location / {
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=$1  last;   break;
        }
        fastcgi_pass  php56;
        fastcgi_index index.php;
        include fcgi.conf;
    }

 

 

1、通过header信息,在nginx获取http_$headerkey

2、根据版本号判断,先添加一个标识/JUMP

3、location匹配,去掉添加的标识,请求转发到其他服务器

4、主意:屏蔽的代码,因为匹配优先级比/JUMP高

 

 

 

 

 

  

posted @ 2020-05-06 16:39  蓝色星辰1993  阅读(2001)  评论(0编辑  收藏  举报