From a98dba11512b9f3cc8cc4dc31b16d4014a95dd16 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sat, 10 Jul 2021 13:46:35 +0800 Subject: [PATCH] change: enable stream proxy only by default Signed-off-by: spacewander --- apisix/cli/ngx_tpl.lua | 2 ++ conf/config-default.yaml | 1 + docs/en/latest/stream-proxy.md | 10 +++++++ docs/zh/latest/stream-proxy.md | 10 +++++++ t/cli/test_admin.sh | 4 +-- t/cli/test_dns.sh | 4 +-- t/cli/test_snippet.sh | 1 + t/cli/test_stream_config.sh | 55 ++++++++++++++++++++++++++++++++++ t/cli/test_tls_over_tcp.sh | 1 + 9 files changed, 84 insertions(+), 4 deletions(-) create mode 100755 t/cli/test_stream_config.sh diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index 166c7a0efc30..99346b7bfbff 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -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 @@ -692,4 +693,5 @@ http { {% end %} # http end configuration snippet ends } +{% end %} ]=] diff --git a/conf/config-default.yaml b/conf/config-default.yaml index eedf77febdfa..1e6268defd45 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -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 diff --git a/docs/en/latest/stream-proxy.md b/docs/en/latest/stream-proxy.md index a02e690f567f..eaef30a4625f 100644 --- a/docs/en/latest/stream-proxy.md +++ b/docs/en/latest/stream-proxy.md @@ -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: diff --git a/docs/zh/latest/stream-proxy.md b/docs/zh/latest/stream-proxy.md index 9455347b16d6..20eb244220de 100644 --- a/docs/zh/latest/stream-proxy.md +++ b/docs/zh/latest/stream-proxy.md @@ -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 ? 简例如下: diff --git a/t/cli/test_admin.sh b/t/cli/test_admin.sh index 9d7dd4ae50ad..caa4f0089657 100755 --- a/t/cli/test_admin.sh +++ b/t/cli/test_admin.sh @@ -36,7 +36,7 @@ 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 @@ -44,7 +44,7 @@ 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 diff --git a/t/cli/test_dns.sh b/t/cli/test_dns.sh index 62985eacc9ce..38c6d7a24970 100755 --- a/t/cli/test_dns.sh +++ b/t/cli/test_dns.sh @@ -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 @@ -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 diff --git a/t/cli/test_snippet.sh b/t/cli/test_snippet.sh index 8a383c95dd48..e103224236f5 100755 --- a/t/cli/test_snippet.sh +++ b/t/cli/test_snippet.sh @@ -27,6 +27,7 @@ apisix: enable_admin: true port_admin: 9180 stream_proxy: + only: false tcp: - 9100 nginx_config: diff --git a/t/cli/test_stream_config.sh b/t/cli/test_stream_config.sh new file mode 100755 index 000000000000..75f56677788f --- /dev/null +++ b/t/cli/test_stream_config.sh @@ -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" diff --git a/t/cli/test_tls_over_tcp.sh b/t/cli/test_tls_over_tcp.sh index 1c7f2559c722..a5a095a52839 100755 --- a/t/cli/test_tls_over_tcp.sh +++ b/t/cli/test_tls_over_tcp.sh @@ -23,6 +23,7 @@ echo " apisix: stream_proxy: + only: false tcp: - addr: 9100 tls: true