nginx tcp proxy <备忘>
2015-07-29 10:48
453 查看
Nginx tcp 代理功能由nginx_tcp_proxy_module模块提供,同时检测后端主机状态。该模块包括的模块有:ngx_tcp_module, ngx_tcp_core_module, ngx_tcp_upstream_module, ngx_tcp_proxy_module, ngx_tcp_upstream_ip_hash_module。
下载nginx_tcp_proxy_module: https://github.com/yaoweibin/nginx_tcp_proxy_module
安装和配置细节看README文件
这样配置会出现一个问题,就是tcp连接会掉线。原因在于当服务器关闭链接的时候,客户端不可能立刻发觉连接已经关闭,需要等到当Nginx在执行check规则时认为服务端连接关闭,此时nginx会关闭与客户端的连接。
保持连接配置:
so_keepalive: The same as so_keepalive <With this directive you can set the socket SO_KEEPALIVE option for the client connection to Nginx.>
tcp_nodelay: The same as tcp_nodelay <这些数据之间不存在延迟,解决网络阻塞,极大地有益于WWW、FTP以及文件服务器的性能>
nginx_tcp_proxy_module模块指令具体参见: http://yaoweibin.github.io/nginx_tcp_proxy_module/README.html '''
使用nginx代理ftp:
只需修改proxy_pass就可以了:
tcp {
timeout 1d;
proxy_read_timeout 10d;
proxy_send_timeout 10d;
proxy_connect_timeout 30;
upstream ftp {
server 192.168.111.46:21;
check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
listen 8080;
proxy_pass ftp;
so_keepalive on;
tcp_nodelay on;
}
$ nginx -s reload
测试:
下载nginx_tcp_proxy_module: https://github.com/yaoweibin/nginx_tcp_proxy_module
安装和配置细节看README文件
tcp { upstream cluster { # simple round-robin server 192.168.111.46:8888; server 192.168.111.46:8889; check interval=3000 rise=2 fall=5 timeout=1000; #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello; #check interval=3000 rise=2 fall=5 timeout=1000 type=http; #check_http_send "GET / HTTP/1.0\r\n\r\n"; #check_http_expect_alive http_2xx http_3xx; } server { listen 8080; proxy_pass cluster; } }
这样配置会出现一个问题,就是tcp连接会掉线。原因在于当服务器关闭链接的时候,客户端不可能立刻发觉连接已经关闭,需要等到当Nginx在执行check规则时认为服务端连接关闭,此时nginx会关闭与客户端的连接。
保持连接配置:
tcp { timeout 1d; proxy_read_timeout 10d; proxy_send_timeout 10d; proxy_connect_timeout 30; #timeout milliseconds upstream cluster { # simple round-robin server 192.168.111.46:8888; server 192.168.111.46:8889; check interval=3000 rise=2 fall=5 timeout=1000; #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello; #check interval=3000 rise=2 fall=5 timeout=1000 type=http; #check_http_send "GET / HTTP/1.0\r\n\r\n"; #check_http_expect_alive http_2xx http_3xx; } server { listen 8080; proxy_pass cluster; so_keepalive on; tcp_nodelay on; } }'''
so_keepalive: The same as so_keepalive <With this directive you can set the socket SO_KEEPALIVE option for the client connection to Nginx.>
tcp_nodelay: The same as tcp_nodelay <这些数据之间不存在延迟,解决网络阻塞,极大地有益于WWW、FTP以及文件服务器的性能>
nginx_tcp_proxy_module模块指令具体参见: http://yaoweibin.github.io/nginx_tcp_proxy_module/README.html '''
使用nginx代理ftp:
只需修改proxy_pass就可以了:
tcp {
timeout 1d;
proxy_read_timeout 10d;
proxy_send_timeout 10d;
proxy_connect_timeout 30;
upstream ftp {
server 192.168.111.46:21;
check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
listen 8080;
proxy_pass ftp;
so_keepalive on;
tcp_nodelay on;
}
$ nginx -s reload
测试:
相关文章推荐
- AFNetworking、MKNetworkKit和ASIHTTPRequest对比
- hdu 1532 网络流
- HTTP 头部解释
- ios网络学习------4 UIWebView的加载本地数据的三种方式
- tomcat 禁用不安全的http请求模式
- 基于网络爬虫的全国气温排行程序/c++
- https 原理简析
- Linux服务之httpd基本配置详解
- Linux服务之httpd基本配置详解
- iOS 关于获取网络类型和运营商信息
- TCP/IP 学习博客
- TCP/IP协议三次握手与四次握手流程解析(转载及总结)
- linux mkdir http://www.linuxidc.com/Linux/2011-04/35180.htm
- 使用HttpClient登录知乎获取返回页面信息
- 使用HttpClient登录知乎获取返回页面信息
- 实例讲解虚拟机3种网络模式(桥接、NAT、host-only)
- UNIX网络编程卷一:第三章 套接字编程简介
- MySQL MYSQL_ROW http://www.cnblogs.com/cy163/archive/2009/04/24/1442859.html
- Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stoc
- python基于协程的网络库gevent、eventlet