Nginx进行路由转发导致的bug

项目场景:

项目场景:项目原本是多租户架构,更改为微服务架构之后,请求的前缀增加了 “/服务名”,前端不想更改url,所以在nginx里进行更改


问题描述

nginx转发之后,接口400,显示是转发成功

        location ~* /(system|department|dict|dictData|induspark|permission|permiTemplate|redis|role|tenant|user|platformFrontPage|thirdpart|app|common|webSocket)/ {
            proxy_read_timeout 600s;
            proxy_pass http://127.0.0.1:8011/blade-auth$docuemnt_uri;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header X-Special-Delivery "";
            proxy_set_header Access-Control-Allow-Origin "";
            proxy_set_header Proxy-Client-IP $remote_addr;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            add_header X-Special-Delivery "stop-polling-our-interface-you-bitch" always;
            add_header Access-Control-Allow-Origin "you-poll-your-mama-blyat" always;
        }

原因分析:

nginx基于$request_uri访问控制,$request_uri比$docuemnt_uri多了请求的参数,主要是针对请求的uri中的参数进行控制


参考文章:

  1. Nginx中的$document_uri与$request_uri以及$http_referer
  2. Nginx proxy_pass详解

解决方案:

修改document_uri为request_uri

        location ~* /(system|department|dict|dictData|induspark|permission|permiTemplate|redis|role|tenant|user|platformFrontPage|thirdpart|app|common|webSocket)/ {
            proxy_read_timeout 600s;
            proxy_pass http://127.0.0.1:8011/blade-auth$request_uri;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header X-Special-Delivery "";
            proxy_set_header Access-Control-Allow-Origin "";
            proxy_set_header Proxy-Client-IP $remote_addr;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            add_header X-Special-Delivery "stop-polling-our-interface-you-bitch" always;
            add_header Access-Control-Allow-Origin "you-poll-your-mama-blyat" always;
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值