it编程 > 数据库 > MsSqlserver

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

75人参与 • 2026-10-09 • MsSqlserver

场景

访问接口地址 --> a服务器 --> a服务器反向代理到b服务器 --> b服务器反向代理到c服务器 --> 获取结果并返回

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

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 服务器反向代理配置

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/;
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

赞 (0)

您想发表意见!!点此发布评论

推荐阅读

CentOS 7如何关闭防火墙命令

10-09

Ubuntu使用chkconfig命令时报错:chkconfig: command not found问题及解决

10-09

PostgreSQL PITR实现时间点误删除恢复功能

10-09

SQL Server备份和恢复从入门到精通的完整指南

10-09

PostgreSQL四种常见部署模式对比详解

10-10

PostgreSQL 的常见锁:为什么你的 ALTER TABLE 会卡住

09-28

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论