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

feature: support multiple ports like stream listen in http and https … #2409

Merged
merged 7 commits into from
Oct 17, 2020
18 changes: 18 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions FAQ_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

29 changes: 24 additions & 5 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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 %}

Expand Down Expand Up @@ -875,6 +882,18 @@ 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 = {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 = {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,
Expand Down