socket - Nginx TCP代理的問題
阿神
阿神 2017-05-16 17:12:03
0
1
600

設備使用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學習者快速成長!