feat: support configurating the node listening address#4856
Conversation
|
@spacewander Hi, PTAL |
nic-chen
left a comment
There was a problem hiding this comment.
@wayne-cheng tanks.need test cases
spacewander
left a comment
There was a problem hiding this comment.
A test under t/cli is in need.
| {% end %} | ||
| {% if ssl.enable then %} | ||
| listen {* item.ip *}:{* item.port *} default_server {% if enable_reuseport then %} reuseport {% end %} {% if item.enable_http2 then %} http2 {% end %}; | ||
| {% if item.allow_ssl and ssl.enable then %} |
There was a problem hiding this comment.
ok,and should I explain these params in the doc FAQ.md ?
apisix:
node_listen:
- 9080
- port: 9380
ip: 127.0.0.1 # If not given, the default is `0.0.0.0`.
enable_ssl: True # If `False`, the ip connot be ued to enable ssl. If not given, the default is `True`.There was a problem hiding this comment.
IMHO, document it in the conf/config-default.yaml as a comment is enough.
There was a problem hiding this comment.
And the default value of "enable_ssl" should not be true, since 9080 doesn't have "enable_ssl", and it doesn't enable SSL by default.
There was a problem hiding this comment.
Actually, we are planning to reduce the length of the current FAQ, let each answer go to suitable places, instead of putting them together.
There was a problem hiding this comment.
It is better to modify the config apisix.ssl.listen_port ,like this:
apisix:
ssl:
listen_port:
- ip: 127.0.0.1
port: 9443The ssl config in the param apisix.node_listen[] could be confusing,for example:
apisix:
node_listen:
- ip: 127.0.0.2
port: 9082
enable_ssl: true
- ip: 127.0.0.2
port: 9083
enable_ssl: falseWhat do you think? @spacewander
There was a problem hiding this comment.
Agree. Personally, I prefer to use a new key "listen" since it is not just with port. Maybe we need to move "enable_http2" under "listen" too. Like this one:
apisix:
ssl:
# enable_http2: false
# listen_port: ...
listen:
- ip: 127.0.0.1
port: 9443
enable_http2: true # per listen configuration
@wayne-cheng
What's your opinion?
There was a problem hiding this comment.
@spacewander
I cannot agree any more. BTW, do I need to consider compatibility with the old configuration about ssl? There are something troublesome to deal with, the new config need to be merged with the old config.
There was a problem hiding this comment.
Yes. We need to keep backward compatibility.
There was a problem hiding this comment.
@spacewander I have updated the code, please take a look.
| node_listen: 9080 # APISIX listening port | ||
| node_listen: # APISIX listening port | ||
| - 9080 | ||
| - ip: 127.0.0.2 # Specific IP, If not set, the default value is `0.0.0.0`. |
There was a problem hiding this comment.
Please comment out the example
| listen_port: 9443 | ||
| listen: | ||
| - 9443 | ||
| - ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`. |
| - ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`. | ||
| port: 9444 | ||
| enable_http2: true # If not set, the default value is `false`. | ||
| #port: 9081 |
There was a problem hiding this comment.
Please remove the irrelative line
| local addr = ip .. ":" .. port | ||
|
|
||
| if ip_port_to_check[addr] == nil then | ||
| table_insert(total_ssl_listen, {ip = ip, port = port, enable_http2 = yaml_conf.apisix.ssl.enable_http2}) |
There was a problem hiding this comment.
We can refactor the repeated code in a function, which accepts enable_http2, enable_ipv6 and other arguments
There was a problem hiding this comment.
Thx, the code is much clearer now
| enable_http2: true # If not set, the default value is `false`. | ||
| #port: 9081 | ||
| #enable_http2: true | ||
| #listen_port: 9443 |
There was a problem hiding this comment.
Need to add a comment to show that this way still supports, but is no longer recommended
There was a problem hiding this comment.
ok,I will comment it like this:
apisix:
node_listen: 9080 # APISIX listening port
# node_listen: # This style support multiple ports
# - 9080
# - ip: 127.0.0.2 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9082
ssl:
enable: true
# listen: # APISIX listening port in https.
# - 9443
# - ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9444
# enable_http2: true # If not set, the default value is `false`.
enable_http2: true # Not recommend: This parameter should be set via the `listen`.
listen_port: 9443 # Not recommend: This parameter should be set via the `listen`.There was a problem hiding this comment.
I prefer to:
apisix:
# node_listen: 9080 # APISIX listening port
node_listen: # This style support multiple ports
- 9080
# - ip: 127.0.0.2 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9082
ssl:
enable: true
listen: # APISIX listening port in https.
- 9443
# - ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9444
# enable_http2: true # If not set, the default value is `false`.
enable_http2: true # Not recommend: This parameter should be set via the `listen`.
# listen_port: 9443 # Not recommend: This parameter should be set via the `listen`.Let's encourage users to use the new style.
| # | ||
|
|
||
| apisix: | ||
| node_listen: 9080 # APISIX listening port |
|
@spacewander A new commit has been pushed, PTAL |
| server { | ||
| {% for _, item in ipairs(node_listen) do %} | ||
| listen {* item.port *} default_server {% if enable_reuseport then %} reuseport {% end %} {% if item.enable_http2 then %} http2 {% end %}; | ||
| listen {* item.ip *}:{* item.port *} default_server {% if enable_reuseport then %} reuseport {% end %}; |
There was a problem hiding this comment.
http port also need to enable_http2
There was a problem hiding this comment.
OK, and it means that the config apisix.node_listen[] also has the property enable_http2 , right?
apisix:
# node_listen: 9080 # APISIX listening port
node_listen: # This style support multiple ports
- 9080
# - ip: 127.0.0.2 # Specific IP, If not set, the default value is `0.0.0.0`.
# port: 9082
# enable_http2: true There was a problem hiding this comment.
it means that the config apisix.node_listen[] also has the property enable_http2 , right?
Yes.
|
|
||
| local node_listen = {{port = yaml_conf.apisix.node_listen}} | ||
| yaml_conf.apisix.node_listen = node_listen | ||
| local addr = ip .. ":" .. port |
There was a problem hiding this comment.
We can add scheme to this key so that we can reduce a branch
There was a problem hiding this comment.
Since the config apisix.node_listen[] also has the property enable_http2, the branch can be reduced.
Port conflicts should be checked at the TCP layer, not the scheme http/https, so the scheme would not be add to this key.
|
The conifg |
| server { | ||
| {%if https_admin then%} | ||
| listen {* port_admin *} ssl; | ||
| {% for _, item in ipairs(ssl.listen) do %} |
There was a problem hiding this comment.
I don't like the idea that the admin requires multiple ports.
There was a problem hiding this comment.
Multiple admin ports are useless. You only need to set one in the API client.
There was a problem hiding this comment.
I did not change the config port_admin. It is still the same as before, only one port_admin can be set.
The idea is to match the specific ip in the config node_listen,not for multiple ports.
|
Please don't change the |
|
@spacewander {% if item.only_admin then %}
listen {* item.ip *}:{* item.port *} ssl;
{% end %}In my environment, the apisix bind the VIP. If the |
|
Maybe we can add an "admin_listen" section like what we have done with |
|
Agree,Of course this way is better. Next, Do I undo the changes about |
|
Yes |
|
OK,PTAL @spacewander |
|
@spacewander apisix:
node_listen: 9081The error will occur when exec ./bin/apisix init
/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua init
failed to read local yaml config of apisix: failed to merge, path[apisix->ssl->listen] expect: table, but got: number
make: *** [Makefile:127: init] Error 1This bug should have existed before, but it was missed, since the previous file -- ...
elseif type(base[key]) ~= type_val then
if (ppath == "nginx_config" or str_sub(ppath, 1, 14) == "nginx_config->") and
(type_val == "number" or type_val == "string")
then
base[key] = val
else
local path = ppath == "" and key or ppath .. "->" .. key
return nil, "failed to merge, path[" .. path .. "] expect: " ..
type(base[key]) .. ", but got: " .. type_val
end
else
base[key] = val
end
-- ... |
|
Thanks for your report. Let's add it to the allow list. I think you can submit it via a separate PR. I can merge it first, so that you are no longer a first-time contributor, then you can see the CI result without approval. |
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
Signed-off-by: wayne-cheng <[email protected]>
8f69513 to
8fbce3c
Compare
| enable: true | ||
| enable_http2: true | ||
| listen_port: 9443 | ||
| # listen: 9443 # APISIX listening port in https. |
There was a problem hiding this comment.
I think we should only support table format for the new configuration, this will make it easier to understand.
There was a problem hiding this comment.
ok,I have removed it in the config-default.yaml.
Signed-off-by: wayne-cheng <[email protected]>
| return true | ||
| end | ||
|
|
||
| if path == "apisix->ssl->listen" and type_val == "number" then |
|
|
||
| local ssl_listen = {} | ||
| -- listen in https, support multiple ports, support specific IP | ||
| if type(yaml_conf.apisix.ssl.listen) == "number" then |
There was a problem hiding this comment.
Got it, the related code has also been removed.
…format Signed-off-by: wayne-cheng <[email protected]>
|
@spacewander Thanks for your patience to review, I'll submit next PR to add the config |
|
Hi, When will this feature be released to the docker image? |
Signed-off-by: wayne-cheng [email protected]
What this PR does / why we need it:
support configurating the node listening address,
The
config.yamlexample as below:Fix #4853
Pre-submission checklist: