【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高

 

 

 

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM