socket - Nginx TCP代理的问题
阿神
阿神 2017-05-16 17:12:03
0
1
621

设备使用1883端口通过nginx 的TCP/UDP 代理转发到后台服务器,
后台服务器查看设备的socket的ip 是代理服务器的ip,而不是设备的实际IP,
怎么实现透明代理,让nginx 代理把设备的实际ip连接后台服务器呢

备注:

  1. 设备连接时拿不到自己的ip,所以不要往这点去想

  2. 是TCP/UDP代理,不是http

阿神
阿神

闭关修行中......

全部回复(1)
巴扎黑

Nginx Stream Module
The ngx_stream_core_module module is available since version 1.9.0. This module is not built by default, it should be enabled with the --with-stream configuration parameter.

这个模块不在默认构建之前,安装nginx时需要增加--with-stream配置。

示例程序

worker_processes auto;

error_log /var/log/nginx/error.log info;

events {
    worker_connections  1024;
}

stream {
    upstream backend {
        hash $remote_addr consistent;

        server backend1.example.com:12345 weight=5;
        server 127.0.0.1:12345            max_fails=3 fail_timeout=30s;
        server unix:/tmp/backend3;
    }

    upstream dns {
       server 192.168.0.1:53535;
       server dns.example.com:53;
    }

    server {
        listen 12345;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass backend;
    }

    server {
        listen 127.0.0.1:53 udp;
        proxy_responses 1;
        proxy_timeout 20s;
        proxy_pass dns;
    }

    server {
        listen [::1]:12345;
        proxy_pass unix:/tmp/stream.socket;
    }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!