nginx搭配gateway的集群配置

一、nginx在http里配置如下信息

复制代码
upstream gateway-cluster {
        server 127.0.0.1:10001;
        server 127.0.0.1:10002;
    }

    server {
        listen       1000;
        server_name  localhost;

        location ~/zzw_project/(.*) {
            proxy_pass http://gateway-cluster/$1;

            proxy_set_header Host $host;  # 代理设置,保留客户端的原始信息
            proxy_pass_request_body on;  #开启获取请求体
            proxy_pass_request_headers on;  #开启获取请求头
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            # 建议增加超时时间设置,避免gateway响应延迟导致请求超时
            proxy_connect_timeout 60s;
            proxy_send_timeout 60s;
            proxy_read_timeout 60s;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

二、搭建gateway服务

三、总结调用过程,以(http://localhost:1000/zzw_project/pay-api/pay/result)为例

localhost:1000首先到nginx监听到,通过location命中,走代理负载后面路径变成http://127.0.0.1:10001/pay-api/pay/result。接下来请求到了网关gateway,/pay-api/pay/result这个路径被接收的路径捕获到,filters一下路径变成/pay/result,加上uri的pay-api(通过向注册中心获取具体的ip和端口)变成http://127.0.0.1:8201/pay/result。

相关推荐
西泽XIZ912 小时前
微信小程序网络与数据库交互实践:从后端环境搭建到数据渲染
网络·数据库·微信小程序·小程序
如夏倾城18 小时前
大模型(Large Model)解析:从数据类型、模型架构到任务选型
服务器·网络·数据库·语言模型·架构·audiolm
Risehuxyc21 小时前
MTU 和 MSS 详解
网络·智能路由器
ikgy1 天前
JAVA EE:7.网络初识
网络
op_qo1 天前
写了几年 OpenResty Lua 网关脚本,聊聊绕不开的 5 个痛点与一种新解法
nginx
AlanAshley1 天前
移动端省流方案:压缩+缓存
网络·缓存
EmbeddedChen1 天前
Linux 怎么查看 IP 地址和网络状态?常用网络命令入门
linux·网络·ip·route·ping
牙牙7051 天前
接口一直超时,后端却查不出问题:TIME_WAIT 把本地端口耗尽了
linux·网络·tcp·连接池·故障排查·time_wait
郝学胜-神的一滴2 天前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
Johny_Zhao2 天前
Keepalived与Nginx架构选型
linux·nginx·信息安全·云计算·apache·shell·yum源·keepalive·系统运维