Nginx配置TCP请求转发

Reading time ~1 minute

1. 概述

通过Nginx对tcp连接进行请求转发.

2. 编译安装 Stream 组建

./configure --prefix=/usr/local/nginx --with-stream  --with-stream_ssl_module

3. 配置Nginx的配置文件conf/nginx.conf

stream {
    upstream proxy_card {
        # simple round-robin  转发IP和端口
        server 192.168.1.12:12340;
        server 192.168.1.13:12340;
        #check interval=3000 rise=2 fall=5 timeout=1000;
        #check interval=3000 rise=2 fall=5timeout=1000
        #check interval=3000 rise=2 fall=5timeout=1000
        #check_http_send "GET /HTTP/1.0\r\n\r\n";
        #check_http_expect_alive http_2xxhttp_3xx;
    }
    server {
        listen 12340; #监听端口
        proxy_pass proxy_card;  #转发请求
    }
}

4. 重启Nginx

./nginx -s stop
./nginx

转载请注明出处:
文章地址: Nginx配置TCP请求转发
作者: mraxu