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。

相关推荐
qq_4523962320 分钟前
【AI 架构师】第十篇:Agent 工业化部署 —— 从 FastAPI 到云端全链路监控
网络·人工智能·ai·fastapi
globaldomain35 分钟前
什么是用于长距离高速传输的TCP窗口扩展?
开发语言·网络·php
桌面运维家2 小时前
Win10打印机共享故障排查:权限与网络配置详解
开发语言·网络·php
众创五舟战神:l_e01203 小时前
shopee(虾皮)买家号系统搭建:安全下单攻略
网络·安全
中议视控3 小时前
RTSP和RTSM编码推送软件让中控系统控制实现可视化播控
网络·分布式·物联网·5g·音视频
追风少年王大爷丶5 小时前
nginx 配置无域名访问拒绝
运维·服务器·nginx
线束线缆组件品替网5 小时前
Amphenol RJE1Y22A53644401线束详解与替代网络线束选型指南
运维·服务器·网络·智能路由器·电脑·51单片机
SeanDe6 小时前
Linux grep 命令用法详解
linux·服务器·网络
志栋智能7 小时前
告别高昂投入:超自动化IT运维的轻量化实践
大数据·运维·网络·人工智能·自动化
没有bug.的程序员9 小时前
S 级 SaaS 平台的物理雪崩:Spring Cloud Gateway 多租户动态路由与 UserID 极限分片
java·gateway·springboot·saas·springcloud·多租户、·userid