OpenResty Edge TCP Load Balancing: Proxy TCP Services Without Editing Nginx Config
OpenResty Edge load-balances TCP services at the stream layer entirely from its Admin console — no stream{} blocks, no upstream or proxy_pass directives, no nginx config editing or reloads. You create a TCP (stream) application, point it at an upstream of backend servers, and OpenResty Edge proxies the connections across its gateway network. In this tutorial we proxy a MySQL server on port 3307 and connect through an edge node to confirm it works. For the complete step-by-step walkthrough, watch the video tutorial on YouTube.
This is the same stream-layer proxying used for the SNI Proxy application type.
Create a TCP (Stream) Application in OpenResty Edge
Let’s go to the OpenResty Edge Admin web console. It is our sample deployment of the console. Every user has their local deployment.
This time, we are going to create an application of type stream.
Let’s enter the stream applications page and create a new application.
We see two types of stream applications: SNI Proxy and TCP.
Our topic today is TCP applications.
SNI Proxy applications will get covered in another tutorial.
Select the type TCP.
We need to specify a port for this application.
First, we need to add this port to the default partition.
Click to edit the default partition, add a new port, and enter 3307 as the port number.
Set the port type to TCP.
After saving, the new port is added to the default partition, and the change is released automatically across the gateway network.
Back in the new application dialog, enter the port we just added and create the application.
Add an Upstream and Page Rule for TCP Load Balancing
Go to the upstream page.
Create a new upstream for our backend server and give it a name, say, tcp_backend.
Here we need the backend server’s IP address.
We’ve already prepared a MySQL server at this IP address. Connecting to it directly confirms it is accessible.
We can now fill out the host field for the backend server.
Enter port number 3307.
We may add more servers to this upstream in the future.
Save this upstream. We can see the tcp_backend upstream is now listed.
Now let’s create a new page rule to use this upstream.
Let’s add a proxy target here.
Select the upstream that we just created.
There are several balancing policies to choose from. Our upstream has only one server, so the balancing policy does not matter here — we just keep the default round-robin policy.
Create this page rule.
We can see the newly created proxy page rule in the page rule list.
The last step is to make a new configuration release, which pushes our pending changes out to all the gateway servers.
Ship it.
Now it is fully synchronized. As we can see, this sample deployment has 14 servers in the gateway network.
We do incremental config synchronization across the whole network, live-updating config on the request level. None of the application-level configuration changes require a server reload, restart, or binary upgrade, so it stays scalable even when many different users make frequent releases.
Test the TCP Proxy: Connect to MySQL Through an Edge Node
Checking all the gateway servers grouped by clusters, we have a node in the United States with an IP address ending in 226. We will test the proxy that we just added using this node.
Now we connect a MySQL client to that edge node on port 3307 — using the node’s IP as the host — and run a select query.
It works as expected! The select query returns through the edge node, so the MySQL backend is accessible just like accessing it directly.
This tutorial load-balances TCP connections within a single upstream, using the same console workflow as the HTTP reverse proxy and load balancer setup. To steer traffic across data centers or regions at the DNS level, see how global server load balancing works in OpenResty Edge.
Frequently Asked Questions
How do I load balance TCP without editing nginx config?
In OpenResty Edge you create a TCP (stream) application in the Admin console, add an upstream of backend servers, and attach a page rule that proxies to it — no stream{} blocks, upstream definitions, or proxy_pass directives are written by hand. Releasing the change pushes it to every gateway server with no reload, restart, or binary upgrade.
Can I proxy a MySQL database through OpenResty Edge?
Yes. In this tutorial the backend is a MySQL server listening on port 3307, and OpenResty Edge proxies TCP connections to it. After the release, connecting a MySQL client to the edge node on port 3307 reaches the database exactly as if you connected to the backend directly.
What is the difference between a TCP application and an SNI Proxy application?
Both are stream applications in OpenResty Edge. A TCP application proxies raw TCP connections on a given port, as shown here. An SNI Proxy application routes TLS traffic by the SNI hostname in the handshake; it is covered in the SNI Proxy application tutorial.
Can a TCP upstream have multiple backend servers?
Yes. The upstream in this tutorial has a single server, so the balancing policy does not matter, but you can add more servers and choose a balancing policy such as round-robin.
What is OpenResty Edge
OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.
If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!
About The Author
Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..
Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.
OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.
As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.






















































