From 63d9b3746b686c4c0adaff79bb9824a4c58af2ce Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Tue, 25 Apr 2023 10:31:47 +0800 Subject: [PATCH 1/7] Updated description for Stream Proxy --- docs/en/latest/stream-proxy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index 0ab87b8df4ef..dc18d4e9cbee 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -21,9 +21,9 @@ title: Stream Proxy # --> -TCP is the protocol for many popular applications and services, such as LDAP, MySQL, and RTMP. UDP (User Datagram Protocol) is the protocol for many popular non-transactional applications, such as DNS, syslog, and RADIUS. +A stream proxy is a type of network proxy that operates at L4, handling data streams rather than discrete packets. It sits between a client and a server and acts as an intermediary, forwarding network traffic in both directions. -APISIX can dynamically load balancing TCP/UDP proxy. In Nginx world, we call TCP/UDP proxy to stream proxy, we followed this statement. +APISIX can serve as a stream proxy. ## How to enable stream proxy? From 8fb47adf74838363d59562737c82e6d5e81a3ed4 Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Tue, 25 Apr 2023 10:44:17 +0800 Subject: [PATCH 2/7] Removed trailing blanks --- docs/en/latest/stream-proxy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index dc18d4e9cbee..f4ae2e2e46aa 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -21,9 +21,9 @@ title: Stream Proxy # --> -A stream proxy is a type of network proxy that operates at L4, handling data streams rather than discrete packets. It sits between a client and a server and acts as an intermediary, forwarding network traffic in both directions. +A stream proxy is a type of network proxy that operates at L4, handling data streams rather than discrete packets. It sits between a client and a server and acts as an intermediary, forwarding network traffic in both directions. -APISIX can serve as a stream proxy. +APISIX can serve as a stream proxy. ## How to enable stream proxy? From 10e0fb403cdecd342f1ac886be404997d37d8c2f Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Wed, 26 Apr 2023 14:48:08 +0800 Subject: [PATCH 3/7] Update stream-proxy.md --- docs/en/latest/stream-proxy.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index f4ae2e2e46aa..f91117d5c2d7 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -21,14 +21,17 @@ title: Stream Proxy # --> -A stream proxy is a type of network proxy that operates at L4, handling data streams rather than discrete packets. It sits between a client and a server and acts as an intermediary, forwarding network traffic in both directions. +A stream proxy operates at the transport layer, handling stream-oriented traffic based on TCP and UDP protocols. -APISIX can serve as a stream proxy. +TCP is used for many applications and services, such as LDAP, MySQL, and RTMP. UDP is used for many popular non-transactional applications, such as DNS, syslog, and RADIUS. + +APISIX can serve as a stream proxy, in addition to its application layer support. ## How to enable stream proxy? -Setting the `stream_proxy` option in `conf/config.yaml`, specify a list of addresses that require dynamic proxy. -By default, no stream proxy is enabled. +Set the `stream_proxy` option in `conf/config.yaml` and specify a list of addresses for which APISIX should act as stream proxy. + +By default, stream proxy is disabled. ```yaml apisix: From 7415a49e8c79f8880222f76d2e36cf011d206daf Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Wed, 26 Apr 2023 14:55:48 +0800 Subject: [PATCH 4/7] Update stream-proxy.md --- docs/en/latest/stream-proxy.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index f91117d5c2d7..fd51658cb8ca 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -21,25 +21,23 @@ title: Stream Proxy # --> -A stream proxy operates at the transport layer, handling stream-oriented traffic based on TCP and UDP protocols. +A stream proxy operates at the transport layer, handling stream-oriented traffic based on TCP and UDP protocols. TCP is used for many applications and services, such as LDAP, MySQL, and RTMP. UDP is used for many popular non-transactional applications, such as DNS, syslog, and RADIUS. -TCP is used for many applications and services, such as LDAP, MySQL, and RTMP. UDP is used for many popular non-transactional applications, such as DNS, syslog, and RADIUS. - -APISIX can serve as a stream proxy, in addition to its application layer support. +APISIX can serve as a stream proxy, in addition to being an application layer proxy. ## How to enable stream proxy? -Set the `stream_proxy` option in `conf/config.yaml` and specify a list of addresses for which APISIX should act as stream proxy. +By default, stream proxy is disabled. -By default, stream proxy is disabled. +To enable the option, add the `stream_proxy` option in `conf/config.yaml` and specify a list of destination addresses for which APISIX should act as stream proxy. ```yaml apisix: - stream_proxy: # TCP/UDP proxy - tcp: # TCP proxy address list + stream_proxy: # TCP/UDP proxy + tcp: - 9100 - "127.0.0.1:9101" - udp: # UDP proxy address list + udp: - 9200 - "127.0.0.1:9211" ``` From 6ac3a3ded5eb9fa6ab72335be6afd4dbb36d7ae5 Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Wed, 26 Apr 2023 15:22:48 +0800 Subject: [PATCH 5/7] Update stream-proxy.md --- docs/en/latest/stream-proxy.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index fd51658cb8ca..69943e383abc 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -55,28 +55,28 @@ apisix: - 9100 ``` -## How to set route? +## How to set a route? -Here is a mini example: +You can create a stream route using the Admin API `/stream_routes` endpoint. For example: ```shell curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { - "remote_addr": "127.0.0.1", + "remote_addr": "192.168.5.3", "upstream": { "nodes": { - "127.0.0.1:1995": 1 + "192.168.4.10:1995": 1 }, "type": "roundrobin" } }' ``` -It means APISIX will proxy the request to `127.0.0.1:1995` which the client remote address is `127.0.0.1`. +With this configuration, APISIX would only forward the request to the upstream service at `192.168.4.10:1995` if and only if the request is sent from `192.168.5.3`. See the next section to learn more about matching options. -For more use cases, please take a look at [test case](https://github.com/apache/apisix/blob/master/t/stream-node/sanity.t). +More examples can be found in [test cases](https://github.com/apache/apisix/blob/master/t/stream-node/sanity.t). -## More route match options +## More route matching options And we can add more options to match a route. Currently stream route configuration supports 3 fields for filtering: From 92bc4f9cc2cc800cf56f6567926c6f0403b51dac Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Wed, 26 Apr 2023 15:46:56 +0800 Subject: [PATCH 6/7] Update stream-proxy.md --- docs/en/latest/stream-proxy.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index 69943e383abc..5b922580a91b 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -72,17 +72,17 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 }' ``` -With this configuration, APISIX would only forward the request to the upstream service at `192.168.4.10:1995` if and only if the request is sent from `192.168.5.3`. See the next section to learn more about matching options. +With this configuration, APISIX would only forward the request to the upstream service at `192.168.4.10:1995` if and only if the request is sent from `192.168.5.3`. See the next section to learn more about filtering options. More examples can be found in [test cases](https://github.com/apache/apisix/blob/master/t/stream-node/sanity.t). -## More route matching options +## More stream route filtering options -And we can add more options to match a route. Currently stream route configuration supports 3 fields for filtering: +Currently there are three attributes in stream routes that can be used for filtering requests: -- server_addr: The address of the APISIX server that accepts the L4 stream connection. -- server_port: The port of the APISIX server that accepts the L4 stream connection. -- remote_addr: The address of client from which the request has been made. +- `server_addr`: The address of the APISIX server that accepts the L4 stream connection. +- `server_port`: The port of the APISIX server that accepts the L4 stream connection. +- `remote_addr`: The address of client from which the request has been made. Here is an example: @@ -102,7 +102,7 @@ curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03 It means APISIX will proxy the request to `127.0.0.1:1995` when the server address is `127.0.0.1` and the server port is equal to `2000`. -Let's take another real world example: +Here is an example with MySQL: 1. Put this config inside `config.yaml` From 129e4b452c04db4cf501588cd57f1c043fa41be2 Mon Sep 17 00:00:00 2001 From: Traky Deng Date: Fri, 28 Apr 2023 05:21:19 +0800 Subject: [PATCH 7/7] Update stream-proxy.md --- docs/en/latest/stream-proxy.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index 5b922580a91b..c68173d09c59 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -27,18 +27,18 @@ APISIX can serve as a stream proxy, in addition to being an application layer pr ## How to enable stream proxy? -By default, stream proxy is disabled. +By default, stream proxy is disabled. -To enable the option, add the `stream_proxy` option in `conf/config.yaml` and specify a list of destination addresses for which APISIX should act as stream proxy. +To enable the option, add the `apisix.stream_proxy` option in `conf/config.yaml` and specify a list of addresses which APISIX should act as a stream proxy and listen for incoming requests. ```yaml apisix: - stream_proxy: # TCP/UDP proxy + stream_proxy: tcp: - - 9100 + - 9100 # listen on 9100 ports of all network interfaces for TCP requests - "127.0.0.1:9101" udp: - - 9200 + - 9200 # listen on 9200 ports of all network interfaces for UDP requests - "127.0.0.1:9211" ``` @@ -49,12 +49,18 @@ If you have set the `enable_admin` to false, and need to enable both HTTP and st ```yaml apisix: enable_admin: false - stream_proxy: # TCP/UDP proxy + stream_proxy: only: false - tcp: # TCP proxy address list + tcp: - 9100 ``` +If `apisix.stream_proxy` is undefined in `conf/config.yaml`, you will encounter an error similar to the following and not be able to add a stream route: + +``` +{"error_msg":"stream mode is disabled, can not add stream routes"} +``` + ## How to set a route? You can create a stream route using the Admin API `/stream_routes` endpoint. For example: