nginx-mapping-headers
根据http header 转发到不同的后端服务
client--> header key --> openresty--> read header key --> location service--> upstream endpoint
demo
upstream user {
server 127.0.0.1:8080;
server 127.0.0.2:8080;
}
upstream order{
server 127.0.0.1:8081;
server 127.0.0.2:8081;
}
map $http_x_svc_key_id $app {
111111111 user ;
999999999 order;
}
server {
listen 80 default_server;
root /var/www/html;
index index.html index.htm;
server_name front.example.org;
charset utf-8;
location /api/svc {
include proxy_params;
proxy_pass http://app;
proxy_redirect off;
# Handle Web Socket connections
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
curl
curl -X GET \
http://192.168.0.48:8010/api/svc/v1/platformList \
-H 'accept: application/json, text/plain, */*' \
-H 'x-ccb-centerid: 111111111' \
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/16545895.html