-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: support configurating the node listening address #4856
Conversation
@spacewander Hi, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wayne-cheng tanks.need test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test under t/cli is in need.
apisix/cli/ngx_tpl.lua
Outdated
{% 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use enable_ssl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, document it in the conf/config-default.yaml as a comment is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to modify the config apisix.ssl.listen_port
,like this:
apisix:
ssl:
listen_port:
- ip: 127.0.0.1
port: 9443
The 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: false
What do you think? @spacewander
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We need to keep backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacewander I have updated the code, please take a look.
conf/config-default.yaml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment out the example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
conf/config-default.yaml
Outdated
listen_port: 9443 | ||
listen: | ||
- 9443 | ||
- ip: 127.0.0.3 # Specific IP, If not set, the default value is `0.0.0.0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
conf/config-default.yaml
Outdated
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the irrelative line
apisix/cli/ops.lua
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, the code is much clearer now
conf/config-default.yaml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add a comment to show that this way still supports, but is no longer recommended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
conf/config-default.yaml
Outdated
@@ -20,7 +20,10 @@ | |||
# | |||
|
|||
apisix: | |||
node_listen: 9080 # APISIX listening port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@spacewander A new commit has been pushed, PTAL |
apisix/cli/ngx_tpl.lua
Outdated
@@ -459,11 +459,11 @@ http { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http port also need to enable_http2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it means that the config apisix.node_listen[] also has the property enable_http2 , right?
Yes.
end | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add scheme to this key so that we can reduce a branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
The conifg |
apisix/cli/ngx_tpl.lua
Outdated
@@ -399,7 +399,11 @@ http { | |||
{% if enable_admin and port_admin then %} | |||
server { | |||
{%if https_admin then%} | |||
listen {* port_admin *} ssl; | |||
{% for _, item in ipairs(ssl.listen) do %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea that the admin requires multiple ports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple admin ports are useless. You only need to set one in the API client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: 9081 The 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 1 This 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
conf/config-default.yaml
Outdated
@@ -115,8 +120,16 @@ apisix: | |||
enable_resolv_search_opt: true # enable search option in resolv.conf | |||
ssl: | |||
enable: true | |||
enable_http2: true | |||
listen_port: 9443 | |||
# listen: 9443 # APISIX listening port in https. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,I have removed it in the config-default.yaml
.
Signed-off-by: wayne-cheng <[email protected]>
apisix/cli/file.lua
Outdated
@@ -126,6 +126,10 @@ local function path_is_multi_type(path, type_val) | |||
return true | |||
end | |||
|
|||
if path == "apisix->ssl->listen" and type_val == "number" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove it now?
apisix/cli/ops.lua
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.yaml
example as below:Fix #4853
Pre-submission checklist: