Nginx tcp proxy module试用
来源:互联网 发布:小学生画图软件 编辑:程序博客网 时间:2024/05/18 01:18
前文Nginx TCP Proxy模块的编译安装描述了如何编译tcp proxy module。现在来实验一下如何用。
首先要创建一个日志目录,因为t该模块的日志默认不在/var/log/nginx目录下
mkdir -p /etc/nginx/logs/
在nginx.conf文件中添加下面一节:
tcp { upstream tcpend { server localhost:7778; check interval=3000 rise=2 fall=5 timeout=1000; } server { listen 7777; proxy_pass tcpend; }}
注意,协议是tcp,不能将配置放在http下面。
然后启动本地的某个tcp程序,监听端口7778。用测试程序发起一个7777的连接请求,测试通过。而且不影响http的代理。
但是这个也有副作用,当服务端关闭连接的时候,客户端不可能立刻发觉连接已经被关闭,需要等到:
当Nginx在执行check规则时认为服务端链接关闭,Nginx会关闭与客户端的连接。
此时客户端才能察觉到连接关闭。好在不影响正常连接,所以不是大问题。
对于Nginx内部的工作原理,由于还没有研究过其实现代码,目前只能推测到此。
下面是check命令的解释:
check syntax: *check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [type=tcp|ssl_hello|smtp|mysql|pop3|imap]* default: *none, if parameters omitted, default parameters are interval=30000 fall=5 rise=2 timeout=1000* context: *upstream* description: Add the health check for the upstream servers. At present, the check method is a simple tcp connect. The parameters' meanings are: * *interval*: the check request's interval time. * *fall*(fall_count): After fall_count check failures, the server is marked down. * *rise*(rise_count): After rise_count check success, the server is marked up. * *timeout*: the check request's timeout. * *type*: the check protocol type: 1. *tcp* is a simple tcp socket connect and peek one byte. 2. *ssl_hello* sends a client ssl hello packet and receives the server ssl hello packet. 3. *http* sends a http request packet, receives and parses the http response to diagnose if the upstream server is alive. 4. *smtp* sends a smtp request packet, receives and parses the smtp response to diagnose if the upstream server is alive. The response begins with '2' should be an OK response. 5. *mysql* connects to the mysql server, receives the greeting response to diagnose if the upstream server is alive. 6. *pop3* receives and parses the pop3 response to diagnose if the upstream server is alive. The response begins with '+' should be an OK response. 7. *imap* connects to the imap server, receives the greeting response to diagnose if the upstream server is alive.
- Nginx tcp proxy module试用
- nginx proxy limit module development --1
- nginx proxy limit module development --2
- nginx proxy limit module development --3
- Nginx TCP Proxy模块的编译安装
- nginx tcp proxy 连接保持设置
- 基于nginx的TCP Proxy实现数据库读写分离
- Build Nginx Http/Tcp proxy server Guide Line
- Aliyun OSS Nginx proxy module(阿里云OSS Nginx 签名代理模块)
- tcp proxy
- 利用 Aliyun OSS Nginx proxy module 实现OSS 图片处理回写功能
- nginx module
- nginx websocket功能试用
- docker nginx jwilder/nginx-proxy
- java版tcp proxy
- delphi tcp http proxy
- nginx proxy https
- Nginx Proxy Cache分析
- HttpWebRequest模拟POST提交防止中文乱码
- windows通过GPRS模块拨号上网流程
- <<SAP内存计算——HANA>> 书评
- 中文截取无乱码、 顺序查找和二分查找函数
- 黑马程序员------Java中单例模式的见解及其应用
- Nginx tcp proxy module试用
- ubuntukylin 13.04下配置android真机调试
- sqlserver常出现的简单小问题
- Android 两Activity之间动画效果(2)---------移动效果
- 与孩子一起学编程07章
- 在安装ia32-libs遇到的问题
- plist字段列表及CFBundleVersion与CFBundleShortVersionString
- 求LOG文件中的TOP N
- 对设计模式的理解