Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: enable stream proxy only by default #4580

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ stream {
}
{% end %}

{% if not (stream_proxy and stream_proxy.only ~= false) then %}
http {
# put extra_lua_path in front of the builtin path
# so user can override the source code
Expand Down Expand Up @@ -692,4 +693,5 @@ http {
{% end %}
# http end configuration snippet ends
}
{% end %}
]=]
1 change: 1 addition & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ apisix:
# more details.
ssl: 'radixtree_sni' # radixtree_sni: match route by SNI(base on radixtree)
#stream_proxy: # TCP/UDP proxy
# only: true # use stream proxy only, don't enable HTTP stuff
# tcp: # TCP proxy port list
# - addr: 9100
# tls: true
Expand Down
10 changes: 10 additions & 0 deletions docs/en/latest/stream-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ apisix:
- "127.0.0.1:9211"
```

If you need to enable both HTTP and stream proxy, set the `only` to false:

```yaml
apisix:
stream_proxy: # TCP/UDP proxy
only: false
tcp: # TCP proxy address list
- 9100
```

## How to set route?

Here is a mini example:
Expand Down
10 changes: 10 additions & 0 deletions docs/zh/latest/stream-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ apisix:
- "127.0.0.1:9211"
```

如果你需要同时启用 HTTP 和 stream 代理,设置 `only` 为 false:

```yaml
apisix:
stream_proxy: # TCP/UDP proxy
only: false
tcp: # TCP proxy address list
- 9100
```

## 如何设置 route ?

简例如下:
Expand Down
4 changes: 2 additions & 2 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ make init

grep "listen 9180 ssl" conf/nginx.conf > /dev/null
if [ ! $? -eq 0 ]; then
echo "failed: failed to enabled https for admin"
echo "failed: failed to enable https for admin"
exit 1
fi

make run

code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} https://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1')
if [ ! $code -eq 200 ]; then
echo "failed: failed to enabled https for admin"
echo "failed: failed to enable https for admin"
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions t/cli/test_dns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ apisix:
make init

count=$(grep -c "resolver 127.0.0.1 \[::1\]:5353 valid=30;" conf/nginx.conf)
if [ "$count" -ne 2 ]; then
if [ "$count" -ne 1 ]; then
echo "failed: dns_resolver_valid doesn't take effect"
exit 1
fi
Expand All @@ -74,7 +74,7 @@ apisix:
make init

count=$(grep -c "resolver 127.0.0.1 \[::1\] \[::2\];" conf/nginx.conf)
if [ "$count" -ne 2 ]; then
if [ "$count" -ne 1 ]; then
echo "failed: can't handle IPv6 resolver w/o bracket"
exit 1
fi
Expand Down
1 change: 1 addition & 0 deletions t/cli/test_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ apisix:
enable_admin: true
port_admin: 9180
stream_proxy:
only: false
tcp:
- 9100
nginx_config:
Expand Down
55 changes: 55 additions & 0 deletions t/cli/test_stream_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

#
# 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.
#

. ./t/cli/common.sh

echo "
apisix:
stream_proxy:
tcp:
- addr: 9100
" > conf/config.yaml

make init

count=$(grep -c "lua_package_path" conf/nginx.conf)
if [ "$count" -ne 1 ]; then
echo "failed: failed to enable stream proxy only by default"
exit 1
fi

echo "passed: enable stream proxy only by default"

echo "
apisix:
stream_proxy:
only: false
tcp:
- addr: 9100
" > conf/config.yaml

make init

count=$(grep -c "lua_package_path" conf/nginx.conf)
if [ "$count" -ne 2 ]; then
echo "failed: failed to enable stream proxy and http proxy"
exit 1
fi

echo "passed: enable stream proxy and http proxy"
1 change: 1 addition & 0 deletions t/cli/test_tls_over_tcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
echo "
apisix:
stream_proxy:
only: false
tcp:
- addr: 9100
tls: true
Expand Down