nginx從1.9.0開始,新增加了一個stream模塊,用來實現四層協議的轉發、代理或者負載均衡等
默認安裝的nginx是沒有開啟stream模塊的,需要在安裝時添加,如果已經安裝了,后續安裝的話,請看這篇文章NGINX的后續模塊添加。
在nginx的解壓包里執行,已添加了stream模塊
./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module\
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-stream \
--with-stream_ssl_module && make j4 && make install
然后修改配置文件
vi /usr/local/nginx/conf/nginx.conf #已省略無關部分 events { worker_connections 1024; } #如有需要可添加多個server stream{ server{ listen 12345 so_keepalive=on; #監聽本機12345端口 proxy_pass 172.14.15.16:12345; #轉發到該ip的12345端口 } } http { include mime.types; default_type application/octet-stream;