配置前需要保证nginx已经安装。
- 打开/etc/nginx/nginx.conf文件
末尾添加include proxy/*.conf;这一行 - /etc/nginx/目录下创建proxy目录,并在proxy目录下创建tcp.py文件
3.tcp.py文件加入以下代码
stream{
upstream testtcp{
hash $remote_addr consistent;
server 127.0.0.1:8881 max_fails=3 fail_timeout=10s;
server 127.0.0.1:8882 max_fails=3 fail_timeout=10s;
server 127.0.0.1:8883 max_fails=3 fail_timeout=10s;
server 127.0.0.1:8884 max_fails=3 fail_timeout=10s;
}
server{
listen 8888;
proxy_connect_timeout 20s;
proxy_timeout 5m;
proxy_pass testtcp;
}
}