nginx在多层服务器代理接口地址的应用

场景:访问接口地址 --> A服务器 --> A服务器反向代理到B服务器 --> B服务器反向代理到C服务器 --> 获取结果并返回

1、A 服务器反向代理配置

nginx 复制代码
server {
    listen 4832;
    server_name _;
    location / {
        proxy_pass http://192.168.25.6:4832/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /file/device/ {
        proxy_pass http://192.168.25.6:9500/energy/;
        proxy_set_header Host $host;
        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;
    }

    #冷水机接口-鉴权
    location /dashboard-lsj-8888/ {
        proxy_pass http://192.168.25.6:8001/dashboard-lsj-8888/;
        proxy_set_header Host $host;
        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;
    }

    #冷水机接口-数据
    location /dashboard-lsj-90/ {
        proxy_pass http://192.168.25.6:8001/dashboard-lsj-90/;
        proxy_set_header accessToken $http_accesstoken;
        proxy_set_header Host $host;
        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;
    }
}

2、B 服务器反向代理配置

nginx 复制代码
location /dashboard-lsj-8888/ {
        proxy_connect_timeout 300s;
        proxy_read_timeout 1800s;
        proxy_send_timeout 600s;
        proxy_set_header   Host             $http_host;
        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;
        proxy_pass http://192.168.53.171:8888/;
}


location /dashboard-lsj-90/ {
        proxy_connect_timeout 300s;
        proxy_read_timeout 1800s;
        proxy_send_timeout 600s;
        proxy_set_header   Host             $http_host;
        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;
        proxy_set_header accessToken $http_accesstoken;
        proxy_pass http://192.168.53.171:90/;
}

*********************************只要思想不滑坡,办法总比困难多*********************************

相关推荐
wno7042 小时前
Nginx禁止蜘蛛程序访问
运维·nginx
csdn_aspnet4 小时前
如何使用 Docker 设置 PostgreSQL
运维·数据库·docker·postgresql·容器
jipinxiaofeihua4 小时前
(文章8) 05章-C++泛型编程(下)
linux·运维·网络
赵文宇(温玉)7 小时前
Docker离线安装
运维·docker·容器
进击的荆棘7 小时前
Linux网络——传输层协议UDP
linux·运维·服务器·网络·udp
Android系统攻城狮9 小时前
FFmpeg深度解析之av_bsf_get_by_name:如何查找码流过滤器?(七十九)
linux·运维·ffmpeg·音视频进阶·ffmpeg音视频
Decay__10 小时前
PostgreSQL 监控体系构建 —— postgres_exporter + Prometheus + Grafana 全栈实战
运维·数据库·sql·postgresql
Decay__11 小时前
PostgreSQL 告警与自动化运维 —— 告警分级收敛、Webhook、定时巡检、脚本库
运维·数据库·sql·postgresql
程序员agions13 小时前
Docker Compose 生产环境配置记录
运维·docker·容器
郝学胜-神的一滴13 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy