diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index b7c1e173..2bfa582c 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -92,11 +92,11 @@ stream { } server { - {% for _, port in ipairs(stream_proxy.tcp or {}) do %} - listen {*port*} {% if enable_reuseport then %} reuseport {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp then %} proxy_protocol {% end %}; + {% for _, addr in ipairs(stream_proxy.tcp or {}) do %} + listen {*addr*} {% if enable_reuseport then %} reuseport {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp then %} proxy_protocol {% end %}; {% end %} - {% for _, port in ipairs(stream_proxy.udp or {}) do %} - listen {*port*} udp {% if enable_reuseport then %} reuseport {% end %}; + {% for _, addr in ipairs(stream_proxy.udp or {}) do %} + listen {*addr*} udp {% if enable_reuseport then %} reuseport {% end %}; {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp_to_upstream then %} diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 43ae3321..d7b5edf4 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -183,15 +183,31 @@ local config_schema = { type = "array", minItems = 1, items = { - type = "integer", - } + anyOf = { + { + type = "integer", + }, + { + type = "string", + }, + }, + }, + uniqueItems = true, }, udp = { type = "array", minItems = 1, items = { - type = "integer", - } + anyOf = { + { + type = "integer", + }, + { + type = "string", + }, + }, + }, + uniqueItems = true, }, } }, diff --git a/conf/config-default.yaml b/conf/config-default.yaml index feda21e4..1aca279d 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -101,10 +101,10 @@ apisix: # stream_proxy: # TCP/UDP proxy # tcp: # TCP proxy port list # - 9100 - # - 9101 + # - "127.0.0.1:9101" # udp: # UDP proxy port list # - 9200 - # - 9211 + # - "127.0.0.1:9201" # dns_resolver: # If not set, read from `/etc/resolv.conf` # - 1.1.1.1 # - 8.8.8.8 diff --git a/t/cli/test_validate_config.sh b/t/cli/test_validate_config.sh index 0a58e502..a18b158a 100755 --- a/t/cli/test_validate_config.sh +++ b/t/cli/test_validate_config.sh @@ -45,5 +45,27 @@ if echo "$out" | grep 'no such file'; then echo "failed: find the certificate correctly" exit 1 fi +make stop echo "passed: find the certificate correctly" + +echo ' +apisix: + node_listen: 9080 + enable_admin: true + port_admin: 9180 + stream_proxy: + tcp: + - "localhost:9100" + udp: + - "127.0.0.1:9101" +' > conf/config.yaml + +out=$(make run 2>&1 || echo "ouch") +if echo "$out" | grep 'ouch'; then + echo "failed: allow configurating address in stream_proxy" + exit 1 +fi +make stop + +echo "passed: allow configurating address in stream_proxy"