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。

1. 安装

 

 

3
4
5
6
# wget http://nginx.org/download/nginx-1.4.4.tar.gz
# tar zxvf nginx-1.4.4.tar.gz
# cd nginx-1.4.4
# ./configure --add-module=/path/to/nginx_tcp_proxy_module
# make
# make install

 

2. 配置

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
;
{
;
}
}
{
{
# simple round-robin
;
;
#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_expect_alive http_2xx http_3xx;
}
{
;
;
}
}

这会出现一个问题,就是tcp连接会掉线。原因在于当服务端关闭连接的时候,客户端不可能立刻发觉连接已经被关闭,需要等到当Nginx在执行check规则时认为服务端链接关闭,此时nginx会关闭与客户端的连接。

3. 保持连接配置

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
;
{
;
}
}
{
;
;
;
;
{
# simple round-robin
;
;
#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_expect_alive http_2xx http_3xx;
}
{
;
;
;
;
}
}

nginx_tcp_proxy_module模块指令具体参见: http://yaoweibin.github.io/nginx_tcp_proxy_module/README.html

相关文章:

  • 2021-08-13
  • 2021-09-28
  • 2021-11-22
  • 2021-07-16
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案