From 9ea2c4ca044fb18fcfcb94f1c472987ce7f814a3 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Tue, 13 Oct 2020 18:45:31 +0800 Subject: [PATCH 1/7] feature: support multiple ports like stream listen in http and https listen port. (#1195) fix #1195 --- FAQ.md | 18 ++++++++++++++++++ FAQ_CN.md | 20 ++++++++++++++++++++ bin/apisix | 31 ++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/FAQ.md b/FAQ.md index 11d13baaa0fa..36c30a11cff4 100644 --- a/FAQ.md +++ b/FAQ.md @@ -270,3 +270,21 @@ If your APISIX node does not open the Admin API, then you can manually load the ```shell apisix reload ``` + +## How to support multiple ports in http and https listen port? + +The Apache APISIX listens to a single port by default. If you need to support http or https to listen to multiple ports, modify the steps: +1. Modify the parameter of http port listen `node_listen`, or https port listen `ssl.listen_port` in conf/config.yaml, style like + ``` + apisix: + node_listen: + - 9080 + - 9081 + - 9082 + ssl: + listen_port: + - 9443 + - 9444 + - 9445 + ``` +2. Restart APISIX diff --git a/FAQ_CN.md b/FAQ_CN.md index 483770a5ec82..d1351b24e529 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -220,3 +220,23 @@ curl http://127.0.0.1:9080/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034 ```shell apisix reload ``` + +## 如何支持http和https多端口监听 +apisix默认监听单端口,如果需要支持http或https监听多端口,修改步骤: + +1、修改conf/config.yaml中的http端口监听的配置参数`node_listen`,或https端口监听的参数`ssl.listen_port`,格式如下 +``` +apisix: + node_listen: + - 9080 + - 9081 + - 9082 + ssl: + listen_port: + - 9443 + - 9444 + - 9445 +``` + +2、重启APISIX + diff --git a/bin/apisix b/bin/apisix index 32519a6b099d..7162234c6d2c 100755 --- a/bin/apisix +++ b/bin/apisix @@ -353,11 +353,14 @@ http { {% end %} server { - listen {* node_listen *} {% if enable_reuseport then %} reuseport {% end %}; + {% for _, port in ipairs(node_listen) do %} + listen {* port *} {% if enable_reuseport then %} reuseport {% end %}; + {% end %} {% if ssl.enable then %} - listen {* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %}; + {% for _, port in ipairs(ssl.listen_port) do %} + listen {* port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %}; + {% end %} {% end %} - {% if proxy_protocol and proxy_protocol.listen_http_port then %} listen {* proxy_protocol.listen_http_port *} proxy_protocol; {% end %} @@ -366,9 +369,13 @@ http { {% end %} {% if enable_ipv6 then %} - listen [::]:{* node_listen *} {% if enable_reuseport then %} reuseport {% end %}; + {% for _, port in ipairs(node_listen) do %} + listen [::]:{* port *} {% if enable_reuseport then %} reuseport {% end %}; + {% end %} {% if ssl.enable then %} - listen [::]:{* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %}; + {% for _, port in ipairs(ssl.listen_port) do %} + listen [::]:{* port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %}; + {% end %} {% end %} {% end %} {% -- if enable_ipv6 %} @@ -875,6 +882,20 @@ Please modify "admin_key" in conf/config.yaml . error("missing apisix.proxy_cache for plugin proxy-cache") end + --support multiple ports listen, compatible with the original style + if type(yaml_conf.apisix.node_listen) == "number" then + local node_listen = table.new(1,0) + table.insert(node_listen, yaml_conf.apisix.node_listen) + yaml_conf.apisix.node_listen = node_listen + end + + if type(yaml_conf.apisix.ssl.listen_port) == "number" then + local listen_port = table.new(1,0) + table.insert(listen_port, yaml_conf.apisix.ssl.listen_port) + yaml_conf.apisix.ssl.listen_port = listen_port + end + + -- Using template.render local sys_conf = { lua_path = pkg_path_org, From 69336dc0689ad276c08feca040154b23722e1e25 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Tue, 13 Oct 2020 22:31:46 +0800 Subject: [PATCH 2/7] feature: support multiple ports like stream listen in http and https listen port. (#1195) fix #1195 --- bin/apisix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/apisix b/bin/apisix index 7162234c6d2c..75c4184dc508 100755 --- a/bin/apisix +++ b/bin/apisix @@ -884,14 +884,12 @@ Please modify "admin_key" in conf/config.yaml . --support multiple ports listen, compatible with the original style if type(yaml_conf.apisix.node_listen) == "number" then - local node_listen = table.new(1,0) - table.insert(node_listen, yaml_conf.apisix.node_listen) + local node_listen = {yaml_conf.apisix.node_listen} yaml_conf.apisix.node_listen = node_listen end if type(yaml_conf.apisix.ssl.listen_port) == "number" then - local listen_port = table.new(1,0) - table.insert(listen_port, yaml_conf.apisix.ssl.listen_port) + local listen_port = {yaml_conf.apisix.ssl.listen_port} yaml_conf.apisix.ssl.listen_port = listen_port end From a815f2de9e77a5af832febcc12efa73e4fc3786b Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 16 Oct 2020 01:39:36 +0800 Subject: [PATCH 3/7] deal with requested changes --- FAQ.md | 17 +++++++++++++---- FAQ_CN.md | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/FAQ.md b/FAQ.md index 36c30a11cff4..c5b89a30ff21 100644 --- a/FAQ.md +++ b/FAQ.md @@ -271,20 +271,29 @@ If your APISIX node does not open the Admin API, then you can manually load the apisix reload ``` -## How to support multiple ports in http and https listen port? +## How to make APISIX listen on multiple ports when handling HTTP or HTTPS requests? -The Apache APISIX listens to a single port by default. If you need to support http or https to listen to multiple ports, modify the steps: -1. Modify the parameter of http port listen `node_listen`, or https port listen `ssl.listen_port` in conf/config.yaml, style like - ``` +By default, APISIX only listens on port 9080 when handling HTTP requests. If you want APISIX to listen on multiple ports, you need to modify the relevant parameters in the configuration file as follows: + +1. Modify the parameter of HTTP port listen `node_listen` in `conf/config.yaml`, style like + + ``` apisix: node_listen: - 9080 - 9081 - 9082 + ``` + + Handling https requests is similar, Modify the parameter of HTTPS port listen `ssl.listen_port` in `conf/config.yaml`, style like + + ``` + apisix: ssl: listen_port: - 9443 - 9444 - 9445 ``` + 2. Restart APISIX diff --git a/FAQ_CN.md b/FAQ_CN.md index d1351b24e529..0285b7190fb0 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -221,22 +221,30 @@ curl http://127.0.0.1:9080/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034 apisix reload ``` -## 如何支持http和https多端口监听 -apisix默认监听单端口,如果需要支持http或https监听多端口,修改步骤: - -1、修改conf/config.yaml中的http端口监听的配置参数`node_listen`,或https端口监听的参数`ssl.listen_port`,格式如下 -``` -apisix: - node_listen: - - 9080 - - 9081 - - 9082 - ssl: - listen_port: - - 9443 - - 9444 - - 9445 -``` - -2、重启APISIX +## 如何让 APISIX 在处理 HTTP 或 HTTPS 请求时监听多个端口 + +默认情况下,APISIX 在处理 HTTP 请求时只监听 9080 端口。如果你想让 APISIX 监听多个端口,你需要修改配置文件中的相关参数,具体步骤如下: + +1. 修改`conf/config.yaml`中 HTTP 端口监听的参数`node_listen`,格式如下 + + ``` + apisix: + node_listen: + - 9080 + - 9081 + - 9082 + ``` + + 处理 HTTPS 请求也类似,修改`conf/config.yaml`中 HTTPS 端口监听的参数``ssl.listen_port``,格式如下 + + ``` + apisix: + ssl: + listen_port: + - 9443 + - 9444 + - 9445 + ``` + +2. 重启 APISIX From 8821bc7523d0b5f857285a66e4cfdea69f045250 Mon Sep 17 00:00:00 2001 From: tuzhengsong Date: Fri, 16 Oct 2020 11:44:43 +0800 Subject: [PATCH 4/7] 1.Perfecting the FAQ grammar; 2.Fix check https://github.com/apache/apisix/pull/2409/checks?check_run_id=1260519517#step:6:125 3.Adding Test Cases; --- .travis/apisix_cli_test.sh | 46 +++++++++++++++++++++++++++++++++++++- FAQ.md | 14 ++++++------ FAQ_CN.md | 11 +++++---- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index ae13fba06ca0..bd5291d212f4 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -169,6 +169,50 @@ if [ ! $? -eq 0 ]; then exit 1 fi + +# check support multiple ports listen in http and https + +echo " +apisix: + node_listen: + - 9080 + - 9081 + - 9082 + ssl: + listen_port: + - 9443 + - 9444 + - 9445 +" > conf/config.yaml + +make init + +count_http_ipv4=`grep -c "listen 908." conf/nginx.conf || true` +if [ $count_http_ipv4 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in http with ipv4" + exit 1 +fi + +count_http_ipv6=`grep -c "listen \[::\]:908." conf/nginx.conf || true` +if [ $count_http_ipv6 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in http with ipv6" + exit 1 +fi + +count_https_ipv4=`grep -c "listen 944. ssl" conf/nginx.conf || true` +if [ $count_https_ipv4 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in https with ipv4" + exit 1 +fi + +count_https_ipv6=`grep -c "listen \[::\]:944. ssl" conf/nginx.conf || true` +if [ $count_https_ipv6 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in https with ipv6" + exit 1 +fi + +echo "passed: support multiple ports listen in http and https" + make run code=$(curl -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') @@ -307,4 +351,4 @@ if [ ! $? -eq 0 ]; then exit 1 fi -echo "pass: show WARNING message if the user used default token and allow any IP to access" +echo "pass: show WARNING message if the user used default token and allow any IP to access" \ No newline at end of file diff --git a/FAQ.md b/FAQ.md index c5b89a30ff21..9f7bde7dc2a8 100644 --- a/FAQ.md +++ b/FAQ.md @@ -275,8 +275,8 @@ apisix reload By default, APISIX only listens on port 9080 when handling HTTP requests. If you want APISIX to listen on multiple ports, you need to modify the relevant parameters in the configuration file as follows: -1. Modify the parameter of HTTP port listen `node_listen` in `conf/config.yaml`, style like - +1. Modify the parameter of HTTP port listen `node_listen` in `conf/config.yaml`, for example: + ``` apisix: node_listen: @@ -284,9 +284,9 @@ By default, APISIX only listens on port 9080 when handling HTTP requests. If you - 9081 - 9082 ``` - - Handling https requests is similar, Modify the parameter of HTTPS port listen `ssl.listen_port` in `conf/config.yaml`, style like - + + Handling HTTPS requests is similar, modify the parameter of HTTPS port listen `ssl.listen_port` in `conf/config.yaml`, for example: + ``` apisix: ssl: @@ -295,5 +295,5 @@ By default, APISIX only listens on port 9080 when handling HTTP requests. If you - 9444 - 9445 ``` - -2. Restart APISIX + +2. Restart APISIX \ No newline at end of file diff --git a/FAQ_CN.md b/FAQ_CN.md index 0285b7190fb0..57bce8cc98ca 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -225,7 +225,7 @@ apisix reload 默认情况下,APISIX 在处理 HTTP 请求时只监听 9080 端口。如果你想让 APISIX 监听多个端口,你需要修改配置文件中的相关参数,具体步骤如下: -1. 修改`conf/config.yaml`中 HTTP 端口监听的参数`node_listen`,格式如下 +1. 修改`conf/config.yaml`中 HTTP 端口监听的参数`node_listen`,示例: ``` apisix: @@ -234,9 +234,9 @@ apisix reload - 9081 - 9082 ``` - - 处理 HTTPS 请求也类似,修改`conf/config.yaml`中 HTTPS 端口监听的参数``ssl.listen_port``,格式如下 - + + 处理 HTTPS 请求也类似,修改`conf/config.yaml`中 HTTPS 端口监听的参数``ssl.listen_port``,示例: + ``` apisix: ssl: @@ -246,5 +246,4 @@ apisix reload - 9445 ``` -2. 重启 APISIX - +2. 重启 APISIX \ No newline at end of file From 7c5e841bf821061791f1400e3bc3c15905b9acd7 Mon Sep 17 00:00:00 2001 From: tuzhengsong Date: Fri, 16 Oct 2020 14:21:59 +0800 Subject: [PATCH 5/7] Try again, CI error:https://github.com/apache/apisix/pull/2409/checks. I don't think it's the code that's causing the problem. --- .travis/apisix_cli_test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index bd5291d212f4..77ec65a4aa3c 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -169,7 +169,6 @@ if [ ! $? -eq 0 ]; then exit 1 fi - # check support multiple ports listen in http and https echo " From dc1b4bdd37e304bd6c560f8c9f73a80cc42c1d62 Mon Sep 17 00:00:00 2001 From: tuzhengsong Date: Fri, 16 Oct 2020 14:50:48 +0800 Subject: [PATCH 6/7] fix CI error:https://github.com/apache/apisix/pull/2409/checks?check_run_id=1262973923 --- .travis/apisix_cli_test.sh | 2 +- FAQ.md | 2 +- FAQ_CN.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index 77ec65a4aa3c..03229ad82062 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -350,4 +350,4 @@ if [ ! $? -eq 0 ]; then exit 1 fi -echo "pass: show WARNING message if the user used default token and allow any IP to access" \ No newline at end of file +echo "pass: show WARNING message if the user used default token and allow any IP to access" diff --git a/FAQ.md b/FAQ.md index 9f7bde7dc2a8..520dc60d80a7 100644 --- a/FAQ.md +++ b/FAQ.md @@ -296,4 +296,4 @@ By default, APISIX only listens on port 9080 when handling HTTP requests. If you - 9445 ``` -2. Restart APISIX \ No newline at end of file +2. Restart APISIX diff --git a/FAQ_CN.md b/FAQ_CN.md index 57bce8cc98ca..eb03f98c9339 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -246,4 +246,4 @@ apisix reload - 9445 ``` -2. 重启 APISIX \ No newline at end of file +2. 重启 APISIX From 1310a9402e68b9fc2e5e2509ae1e905ebe4886e6 Mon Sep 17 00:00:00 2001 From: tuzhengsong Date: Fri, 16 Oct 2020 15:55:41 +0800 Subject: [PATCH 7/7] fix CI error:https://github.com/apache/apisix/pull/2409/checks?check_run_id=1263070347 --- .travis/apisix_cli_test.sh | 86 +++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index 03229ad82062..d58aeeed03c8 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -78,6 +78,49 @@ fi echo "passed: change default ssl port" +# check support multiple ports listen in http and https + +echo " +apisix: + node_listen: + - 9080 + - 9081 + - 9082 + ssl: + listen_port: + - 9443 + - 9444 + - 9445 +" > conf/config.yaml + +make init + +count_http_ipv4=`grep -c "listen 908." conf/nginx.conf || true` +if [ $count_http_ipv4 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in http with ipv4" + exit 1 +fi + +count_http_ipv6=`grep -c "listen \[::\]:908." conf/nginx.conf || true` +if [ $count_http_ipv6 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in http with ipv6" + exit 1 +fi + +count_https_ipv4=`grep -c "listen 944. ssl" conf/nginx.conf || true` +if [ $count_https_ipv4 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in https with ipv4" + exit 1 +fi + +count_https_ipv6=`grep -c "listen \[::\]:944. ssl" conf/nginx.conf || true` +if [ $count_https_ipv6 -ne 3 ]; then + echo "failed: failed to support multiple ports listen in https with ipv6" + exit 1 +fi + +echo "passed: support multiple ports listen in http and https" + # check default env echo " nginx_config: @@ -169,49 +212,6 @@ if [ ! $? -eq 0 ]; then exit 1 fi -# check support multiple ports listen in http and https - -echo " -apisix: - node_listen: - - 9080 - - 9081 - - 9082 - ssl: - listen_port: - - 9443 - - 9444 - - 9445 -" > conf/config.yaml - -make init - -count_http_ipv4=`grep -c "listen 908." conf/nginx.conf || true` -if [ $count_http_ipv4 -ne 3 ]; then - echo "failed: failed to support multiple ports listen in http with ipv4" - exit 1 -fi - -count_http_ipv6=`grep -c "listen \[::\]:908." conf/nginx.conf || true` -if [ $count_http_ipv6 -ne 3 ]; then - echo "failed: failed to support multiple ports listen in http with ipv6" - exit 1 -fi - -count_https_ipv4=`grep -c "listen 944. ssl" conf/nginx.conf || true` -if [ $count_https_ipv4 -ne 3 ]; then - echo "failed: failed to support multiple ports listen in https with ipv4" - exit 1 -fi - -count_https_ipv6=`grep -c "listen \[::\]:944. ssl" conf/nginx.conf || true` -if [ $count_https_ipv6 -ne 3 ]; then - echo "failed: failed to support multiple ports listen in https with ipv6" - exit 1 -fi - -echo "passed: support multiple ports listen in http and https" - make run code=$(curl -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')