socket - Issues with Nginx TCP proxy
阿神
阿神 2017-05-16 17:12:03
0
1
664

The device uses port 1883 to forward to the backend server through nginx's TCP/UDP proxy.
The backend server checks the device's socket IP and it is the IP of the proxy server, not the actual IP of the device.
How to implement transparent proxy ,Let the nginx agent connect the actual IP of the device to the backend server?

Remark:

  1. The device cannot get its own IP when connecting, so don’t think about it

  2. is a TCP/UDP proxy, not http

阿神
阿神

闭关修行中......

reply all(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.

This module is not included in the default build. You need to add --with-streamconfiguration when installing nginx.

Example program

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;
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template