nginx通過stream模塊實現反向代理


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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM