-
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
Changes from 12 commits
c0cb6c4
bc80dd8
36349f2
51725ba
7183796
72f0b9f
589eed8
8fbce3c
8427e03
e645a1d
19fd1fa
8de3c80
b3a4e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,45 +461,132 @@ Please modify "admin_key" in conf/config.yaml . | |
end | ||
end | ||
|
||
-- support multiple ports listen, compatible with the original style | ||
if type(yaml_conf.apisix.node_listen) == "number" then | ||
local ip_port_to_check = {} | ||
|
||
local function listen_table_insert(listen_table, scheme, ip, port, enable_http2, enable_ipv6) | ||
if type(ip) ~= "string" then | ||
util.die(scheme, " listen ip format error, must be string", "\n") | ||
end | ||
|
||
if type(port) ~= "number" then | ||
util.die(scheme, " listen port format error, must be number", "\n") | ||
end | ||
|
||
if ports_to_check[port] ~= nil then | ||
util.die(scheme, " listen port ", port, " conflicts with ", | ||
ports_to_check[port], "\n") | ||
end | ||
|
||
local addr = ip .. ":" .. port | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Since the config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
if ports_to_check[yaml_conf.apisix.node_listen] ~= nil then | ||
util.die("node_listen port ", yaml_conf.apisix.node_listen, | ||
" conflicts with ", ports_to_check[yaml_conf.apisix.node_listen], "\n") | ||
if ip_port_to_check[addr] == nil then | ||
table_insert(listen_table, | ||
{ip = ip, port = port, enable_http2 = enable_http2}) | ||
ip_port_to_check[addr] = scheme | ||
end | ||
|
||
local node_listen = {{port = yaml_conf.apisix.node_listen}} | ||
yaml_conf.apisix.node_listen = node_listen | ||
if enable_ipv6 then | ||
ip = "[::]" | ||
addr = ip .. ":" .. port | ||
|
||
if ip_port_to_check[addr] == nil then | ||
table_insert(listen_table, | ||
{ip = ip, port = port, enable_http2 = enable_http2}) | ||
ip_port_to_check[addr] = scheme | ||
end | ||
end | ||
end | ||
|
||
local node_listen = {} | ||
-- listen in http, support multiple ports and specific IP, compatible with the original style | ||
if type(yaml_conf.apisix.node_listen) == "number" then | ||
listen_table_insert(node_listen, "http", "0.0.0.0", yaml_conf.apisix.node_listen, | ||
false, yaml_conf.apisix.enable_ipv6) | ||
elseif type(yaml_conf.apisix.node_listen) == "table" then | ||
local node_listen = {} | ||
for index, value in ipairs(yaml_conf.apisix.node_listen) do | ||
for _, value in ipairs(yaml_conf.apisix.node_listen) do | ||
if type(value) == "number" then | ||
listen_table_insert(node_listen, "http", "0.0.0.0", value, | ||
false, yaml_conf.apisix.enable_ipv6) | ||
elseif type(value) == "table" then | ||
local ip = value.ip | ||
local port = value.port | ||
local enable_ipv6 = false | ||
local enable_http2 = value.enable_http2 | ||
|
||
if ip == nil then | ||
ip = "0.0.0.0" | ||
if yaml_conf.apisix.enable_ipv6 then | ||
enable_ipv6 = true | ||
end | ||
end | ||
|
||
if port == nil then | ||
port = 9080 | ||
end | ||
|
||
if ports_to_check[value] ~= nil then | ||
util.die("node_listen port ", value, " conflicts with ", | ||
ports_to_check[value], "\n") | ||
if enable_http2 == nil then | ||
enable_http2 = false | ||
end | ||
|
||
table_insert(node_listen, index, {port = value}) | ||
listen_table_insert(node_listen, "http", ip, port, | ||
enable_http2, enable_ipv6) | ||
end | ||
end | ||
end | ||
yaml_conf.apisix.node_listen = node_listen | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Got it, the related code has also been removed. |
||
listen_table_insert(ssl_listen, "https", "0.0.0.0", yaml_conf.apisix.ssl.listen, | ||
yaml_conf.apisix.ssl.enable_http2, yaml_conf.apisix.enable_ipv6) | ||
elseif type(yaml_conf.apisix.ssl.listen) == "table" then | ||
for _, value in ipairs(yaml_conf.apisix.ssl.listen) do | ||
if type(value) == "number" then | ||
listen_table_insert(ssl_listen, "https", "0.0.0.0", value, | ||
yaml_conf.apisix.ssl.enable_http2, yaml_conf.apisix.enable_ipv6) | ||
elseif type(value) == "table" then | ||
local ip = value.ip | ||
local port = value.port | ||
local enable_ipv6 = false | ||
local enable_http2 = (value.enable_http2 or yaml_conf.apisix.ssl.enable_http2) | ||
|
||
if ip == nil then | ||
ip = "0.0.0.0" | ||
if yaml_conf.apisix.enable_ipv6 then | ||
enable_ipv6 = true | ||
end | ||
end | ||
|
||
if port == nil then | ||
port = 9443 | ||
end | ||
|
||
if type(value.port) == "number" and ports_to_check[value.port] ~= nil then | ||
util.die("node_listen port ", value.port, " conflicts with ", | ||
ports_to_check[value.port], "\n") | ||
if enable_http2 == nil then | ||
enable_http2 = false | ||
end | ||
|
||
table_insert(node_listen, index, value) | ||
listen_table_insert(ssl_listen, "https", ip, port, | ||
enable_http2, enable_ipv6) | ||
end | ||
end | ||
yaml_conf.apisix.node_listen = node_listen | ||
end | ||
|
||
-- listen in https, compatible with the original style | ||
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 | ||
listen_table_insert(ssl_listen, "https", "0.0.0.0", yaml_conf.apisix.ssl.listen_port, | ||
yaml_conf.apisix.ssl.enable_http2, yaml_conf.apisix.enable_ipv6) | ||
elseif type(yaml_conf.apisix.ssl.listen_port) == "table" then | ||
for _, value in ipairs(yaml_conf.apisix.ssl.listen_port) do | ||
if type(value) == "number" then | ||
listen_table_insert(ssl_listen, "https", "0.0.0.0", value, | ||
yaml_conf.apisix.ssl.enable_http2, yaml_conf.apisix.enable_ipv6) | ||
end | ||
end | ||
end | ||
|
||
yaml_conf.apisix.ssl.listen = ssl_listen | ||
|
||
if yaml_conf.apisix.ssl.ssl_trusted_certificate ~= nil then | ||
local cert_path = yaml_conf.apisix.ssl.ssl_trusted_certificate | ||
-- During validation, the path is relative to PWD | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,7 @@ Instance report fails | |
ngx.status = code | ||
end | ||
ngx.say(body) | ||
ngx.sleep(0.1) | ||
} | ||
} | ||
--- request | ||
|
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?