|
9 | 9 | - how-to |
10 | 10 | --- |
11 | 11 |
|
12 | | -<span id="intro"></span> |
13 | | -## Introduction |
| 12 | +## Introduction {#intro} |
14 | 13 |
|
15 | | -[Load balancing](https://www.nginx.com/solutions/load-balancing/) refers to efficiently distributing network traffic across multiple backend servers. |
| 14 | +[Load balancing](https://www.f5.com/glossary/load-balancer) refers to efficiently distributing network traffic across multiple backend servers. |
16 | 15 |
|
17 | 16 | In F5 NGINX Plus [R5]({{< ref "nginx/releases.md#r5" >}}) and later, NGINX Plus can proxy and load balance Transmission Control Protocol) (TCP) traffic. TCP is the protocol for many popular applications and services, such as LDAP, MySQL, and RTMP. |
18 | 17 |
|
19 | 18 | In NGINX Plus [R9]({{< ref "nginx/releases.md#r9" >}}) and later, NGINX Plus can proxy and load balance UDP traffic. UDP (User Datagram Protocol) is the protocol for many popular non-transactional applications, such as DNS, syslog, and RADIUS. |
20 | 19 |
|
21 | 20 | To load balance HTTP traffic, refer to the [HTTP Load Balancing]({{< ref "http-load-balancer.md" >}}) article. |
22 | 21 |
|
23 | | -<span id="prerequisites"></span> |
24 | 22 | ## Prerequisites |
25 | 23 |
|
26 | 24 | - Latest NGINX Plus (no extra build steps required) or latest [NGINX Open Source](https://nginx.org/en/download.html) built with the `--with-stream` configuration flag |
27 | 25 | - An application, database, or service that communicates over TCP or UDP |
28 | 26 | - Upstream servers, each running the same instance of the application, database, or service |
29 | 27 |
|
30 | | -<span id="proxy_pass"></span> |
31 | | -## Configuring Reverse Proxy |
| 28 | +## Configuring reverse proxy {#proxy_pass} |
32 | 29 |
|
33 | 30 | First, you will need to configure _reverse proxy_ so that NGINX Plus or NGINX Open Source can forward TCP connections or UDP datagrams from clients to an upstream group or a proxied server. |
34 | 31 |
|
@@ -118,8 +115,7 @@ Open the NGINX configuration file and perform the following steps: |
118 | 115 | } |
119 | 116 | ``` |
120 | 117 |
|
121 | | -<span id="upstream"></span> |
122 | | -## Configuring TCP or UDP Load Balancing |
| 118 | +## Configuring TCP or UDP load balancing {#upstream} |
123 | 119 |
|
124 | 120 | To configure load balancing: |
125 | 121 |
|
@@ -250,17 +246,15 @@ stream { |
250 | 246 | } |
251 | 247 | ``` |
252 | 248 |
|
253 | | -<span id="health"></span> |
254 | | -## Configuring Health Checks |
| 249 | +## Configuring health checks {#health} |
255 | 250 |
|
256 | 251 | NGINX can continually test your TCP or UDP upstream servers, avoid the servers that have failed, and gracefully add the recovered servers into the load‑balanced group. |
257 | 252 |
|
258 | 253 | See [TCP Health Checks]({{< ref "nginx/admin-guide/load-balancer/tcp-health-check.md" >}}) for instructions how to configure health checks for TCP. |
259 | 254 |
|
260 | 255 | See [UDP Health Checks]({{< ref "nginx/admin-guide/load-balancer/udp-health-check.md" >}}) for instructions how to configure health checks for UDP. |
261 | 256 |
|
262 | | -<span id="on-the-fly-configuration"></span> |
263 | | -## On-the-Fly Configuration |
| 257 | +## On-the-fly configuration |
264 | 258 |
|
265 | 259 | Upstream server groups can be easily reconfigured on-the-fly using NGINX Plus REST API. Using this interface, you can view all servers in an upstream group or a particular server, modify server parameters, and add or remove upstream servers. |
266 | 260 |
|
@@ -355,8 +349,7 @@ To enable on-the-fly configuration: |
355 | 349 | } |
356 | 350 | ``` |
357 | 351 |
|
358 | | -<span id="on-the-fly-configuration-example"></span> |
359 | | -### On-the-Fly Configuration Example |
| 352 | +### On-the-fly configuration example |
360 | 353 |
|
361 | 354 | ```nginx |
362 | 355 | stream { |
@@ -403,23 +396,22 @@ For example, to add a new server to the server group, send a `POST` request: |
403 | 396 | curl -X POST -d '{ \ |
404 | 397 | "server": "appserv3.example.com:12345", \ |
405 | 398 | "weight": 4 \ |
406 | | - }' -s 'http://127.0.0.1/api/6/stream/upstreams/appservers/servers' |
| 399 | + }' -s 'http://127.0.0.1/api/9/stream/upstreams/appservers/servers' |
407 | 400 | ``` |
408 | 401 |
|
409 | 402 | To remove a server from the server group, send a `DELETE` request: |
410 | 403 |
|
411 | 404 | ```shell |
412 | | -curl -X DELETE -s 'http://127.0.0.1/api/6/stream/upstreams/appservers/servers/0' |
| 405 | +curl -X DELETE -s 'http://127.0.0.1/api/9/stream/upstreams/appservers/servers/0' |
413 | 406 | ``` |
414 | 407 |
|
415 | 408 | To modify a parameter for a specific server, send a `PATCH` request: |
416 | 409 |
|
417 | 410 | ```shell |
418 | | -curl -X PATCH -d '{ "down": true }' -s 'http://127.0.0.1/api/6/http/upstreams/appservers/servers/0' |
| 411 | +curl -X PATCH -d '{ "down": true }' -s 'http://127.0.0.1/api/9/http/upstreams/appservers/servers/0' |
419 | 412 | ``` |
420 | 413 |
|
421 | | -<span id="example"></span> |
422 | | -## Example of TCP and UDP Load-Balancing Configuration |
| 414 | +## Example of TCP and UDP load-balancing configuration {#example} |
423 | 415 |
|
424 | 416 | This is a configuration example of TCP and UDP load balancing with NGINX: |
425 | 417 |
|
@@ -471,3 +463,13 @@ The three [`server`](https://nginx.org/en/docs/stream/ngx_stream_upstream_module |
471 | 463 | - The second server listens on port 53 and proxies all UDP datagrams (the `udp` parameter to the `listen` directive) to an upstream group called **dns_servers**. If the `udp` parameter is not specified, the socket listens for TCP connections. |
472 | 464 |
|
473 | 465 | - The third virtual server listens on port 12346 and proxies TCP connections to **backend4.example.com**, which can resolve to several IP addresses that are load balanced with the Round Robin method. |
| 466 | + |
| 467 | +## See also |
| 468 | + |
| 469 | +- [TCP Health Checks]({{< relref "tcp-health-check.md" >}}) |
| 470 | + |
| 471 | +- [UDP Health Checks]({{< relref "udp-health-check.md" >}}) |
| 472 | + |
| 473 | +- [Load Balancing DNS Traffic with NGINX and NGINX Plus](https://www.f5.com/company/blog/nginx/load-balancing-dns-traffic-nginx-plus) |
| 474 | + |
| 475 | +- [TCP/UDP Load Balancing with NGINX: Overview, Tips, and Tricks](https://blog.nginx.org/blog/tcp-load-balancing-udp-load-balancing-nginx-tips-tricks) |
0 commit comments