项目场景:
项目场景:项目原本是多租户架构,更改为微服务架构之后,请求的前缀增加了 “/服务名”,前端不想更改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中的参数进行控制
参考文章:
解决方案:
修改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;
}