Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of using nginx to do tcp/udp load balancing

Shulou Source: shulou.com Published: 2022-06-02 09:03:04 10月14日 Update

This article mainly introduces "the method of using nginx to do tcp/udp Load Balancer". In daily operation, I believe many people have doubts about the method of using nginx to do tcp/udp Load Balancer. The editor consulted all kinds of information and sorted out simple and easy operation methods. I hope to answer your doubts about "the method of using nginx to do tcp/udp Load Balancer"! Next, please follow the small series to learn together!

Goal: Load Balancer for non-http traffic

Optional technology: nginx + docker-compose,,,

Process:

Load tcp/udp traffic needs to be rebuilt nginx, the original official website is built with the --with-stream, so I found several Dockerfiles with parameters, most of which are articles from six months and a year ago, mirroring is not the focus, and debugging is time-consuming and laborious. It's better to find an officially built version directly, and it's not too late to build your own mirror after Load Balancer testing.

Search docker hub, nginx default image does not have--with-stream parameter, also did not find similar extension tag, continue to search docker nginx --with-stream

Finally found openrest, the default dockerfile with this parameter, the final docker-compose.yml is as follows

version: "3"services: openresty: image: openresty/openresty volumes: - ./ conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf - ./ var/run/openresty/:/var/run/openresty/ ports: - "0.0.0.0:8888:8888"

Add port payload content similar to the following format to nginx.conf

stream { server { listen 8888 ; proxy_timeout 20s; proxy_pass 192.168.1.101:8888; } server { listen 8899 udp reuseport; proxy_timeout 20s; proxy_pass 192.168.1.101:8899; }}

Execute docker-compose up -d in the directory containing the docker-compose.yml file

Check to see if the host port is up and testing the connection

At this point, the study of "using nginx to do tcp/udp Load Balancer" is over, I hope to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Balance method learning parameters mirroring articles more traffic ports help testing practical next content half a year original official host host technology Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Apple Shulou Technology Redmi