vivion27 发表于 2017-12-22 19:32:12

思而不学则殆

  Nginx支持四层代理
  http://nginx.org/en/docs/stream/ngx_stream_core_module.html
  该ngx_stream_core_module模块自1.9.0版开始可用。默认情况下,此模块不构建,应使用配置参数启用 --with-stream 。

  

# tar xf nginx-1.10.3.tar.gz  
[iyunv@linux
-node1 src]# cd nginx-1.10.3  
[iyunv@linux
-node1 nginx-1.10.3]# useradd -s /sbin/nologin -M www  
[iyunv@linux
-node1 nginx-1.10.3]# yum -y install pcre-devel openssl-devel  
[iyunv@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  
[iyunv@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;
  }
  }
  


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

  

  

  

  
[iyunv@linux
-node1 conf]# ssh -p 2222 root@192.168.230.130  
root@
192.168.230.130's password:  
Last login: Sat Apr8 22:32:14 2017 from linux-node1
  
# ls
  
anaconda-ks.cfghello.py
  
页: [1]
查看完整版本: 思而不学则殆