Nginx四層代理


Nginx支持四層代理

http://nginx.org/en/docs/stream/ngx_stream_core_module.html

ngx_stream_core_module模塊自1.9.0版開始可用。默認情況下,此模塊不構建,應使用配置參數啟用 --with-stream 。

 

[root@linux-node1 src]# tar xf nginx-1.10.3.tar.gz 
[root@linux-node1 src]# cd nginx-1.10.3
[root@linux-node1 nginx-1.10.3]# useradd -s /sbin/nologin -M www
[root@linux-node1 nginx-1.10.3]# yum install gcc gcc-c++ zlib-devel pcre-devel openssl openssl-devel -y
[root@linux-node1 nginx-1.10.3]# ./configure --prefix=/usr/local/nginx-1.10.3 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-stream
[root@linux-node1 nginx-1.10.3]# make && make install 

配置文件
worker_processes  1;
events {
    worker_connections  1024;
}
stream {  
        upstream tcp_proxy {
        hash $remote_addr consistent;  #遠程地址做個hash
        server 192.168.230:131:22;
   }
      server {
        listen 2222;
        proxy_connect_timeout 1s;
        proxy_timeout 10s;  #后端連接超時時間
        proxy_pass tcp_proxy;
     }
  }

  
  [root@linux-node1 conf]# /usr/local/nginx-1.10.3/sbin/nginx 
  
  [root@linux-node1 conf]# netstat -ntpl|grep 2222
tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN      12045/nginx: master 




[root@linux-node1 conf]# ssh -p 2222 root@192.168.230.130
root@192.168.230.130's password: 
Last login: Sat Apr  8 22:32:14 2017 from linux-node1
[root@linux-node2 ~]# ls
anaconda-ks.cfg  hello.py

 


免責聲明!

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



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