2019-10-31 09:27:28 +08:00
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
2019-11-24 21:15:39 +08:00
[Chinese ](stream-proxy-cn.md )
2019-09-26 15:08:21 +08:00
2019-09-12 13:27:18 +08:00
# 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.
2019-11-01 09:49:09 +08:00
APISIX can dynamic load balancing TCP/UDP proxy. In Nginx world, we call TCP/UDP proxy to stream proxy, we followed this statement.
2019-09-12 13:27:18 +08:00
## 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 any stream proxy is enabled.
```
apisix:
stream_proxy: # TCP/UDP proxy
tcp: # TCP proxy address list
- 9100
- 127.0.0.1:9101
udp: # UDP proxy address list
- 9200
- 127.0.0.1:9211
```
## How to set route?
Here is a mini example:
```shell
curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -X PUT -d '
{
"remote_addr": "127.0.0.1",
"upstream": {
"nodes": {
"127.0.0.1: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` .
For more use cases, please take a look at [test case ](../t/stream-node/sanity.t ).
2019-09-16 13:03:26 +08:00
## More Limit Options
And we can add more limit options to match a route, here is an example:
```shell
curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -X PUT -d '
{
"server_addr": "127.0.0.1",
"server_port": 2000,
"upstream": {
"nodes": {
"127.0.0.1:1995": 1
},
"type": "roundrobin"
}
}'
```
It means APISIX will proxy the request to `127.0.0.1:1995` which the server remote address is `127.0.0.1` and the server port is equal `2000` .