diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index ea0366a41..8ed7a470a 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -17,6 +17,7 @@ File format: - Fix rule-engine update behaviour which may initialize actions for disabled rules. [#8849](https://github.com/emqx/emqx/pull/8849) - Fix JWT plugin don't support non-integer timestamp claims. [#8862](https://github.com/emqx/emqx/pull/8862) - Fix a possible dead loop caused by shared subscriptions with `shared_dispatch_ack_enabled=true`. [#8918](https://github.com/emqx/emqx/pull/8918) +- Fix dashboard binding IP address not working. [#8916](https://github.com/emqx/emqx/pull/8916) ## v4.3.19 diff --git a/lib-ce/emqx_dashboard/priv/emqx_dashboard.schema b/lib-ce/emqx_dashboard/priv/emqx_dashboard.schema index 43093c3ba..7ef39ac8d 100644 --- a/lib-ce/emqx_dashboard/priv/emqx_dashboard.schema +++ b/lib-ce/emqx_dashboard/priv/emqx_dashboard.schema @@ -11,7 +11,7 @@ ]}. {mapping, "dashboard.listener.http", "emqx_dashboard.listeners", [ - {datatype, integer} + {datatype, [integer, ip]} ]}. {mapping, "dashboard.listener.http.acceptors", "emqx_dashboard.listeners", [ @@ -39,7 +39,7 @@ ]}. {mapping, "dashboard.listener.https", "emqx_dashboard.listeners", [ - {datatype, integer} + {datatype, [integer, ip]} ]}. {mapping, "dashboard.listener.https.acceptors", "emqx_dashboard.listeners", [ diff --git a/lib-ce/emqx_dashboard/src/emqx_dashboard.erl b/lib-ce/emqx_dashboard/src/emqx_dashboard.erl index c4a774072..d88bd0da9 100644 --- a/lib-ce/emqx_dashboard/src/emqx_dashboard.erl +++ b/lib-ce/emqx_dashboard/src/emqx_dashboard.erl @@ -54,7 +54,8 @@ start_listener({Proto, Port, Options}) when Proto == https -> {"/api/v4/[...]", minirest, http_handlers()}], minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch). -ranch_opts(Port, Options0) -> +ranch_opts(Bind, Options0) -> + IpPort = ip_port(Bind), NumAcceptors = get_value(num_acceptors, Options0, 4), MaxConnections = get_value(max_connections, Options0, 512), Options = lists:foldl(fun({K, _V}, Acc) when K =:= max_connections orelse K =:= num_acceptors -> @@ -68,7 +69,13 @@ ranch_opts(Port, Options0) -> end, [], Options0), #{num_acceptors => NumAcceptors, max_connections => MaxConnections, - socket_opts => [{port, Port} | Options]}. + socket_opts => IpPort ++ Options}. + +ip_port({IpStr, Port}) -> + {ok, Ip} = inet:parse_address(IpStr), + [{ip, Ip}, {port, Port}]; +ip_port(Port) when is_integer(Port) -> + [{port, Port}]. stop_listeners() -> lists:foreach(fun(Listener) -> stop_listener(Listener) end, listeners()). diff --git a/lib-ce/emqx_dashboard/test/emqx_dashboard_SUITE.erl b/lib-ce/emqx_dashboard/test/emqx_dashboard_SUITE.erl index 778cb7731..b1a8c0194 100644 --- a/lib-ce/emqx_dashboard/test/emqx_dashboard_SUITE.erl +++ b/lib-ce/emqx_dashboard/test/emqx_dashboard_SUITE.erl @@ -326,7 +326,12 @@ setup_node(Node, Apps) -> application:set_env(emqx_management, listeners, []), ok; (emqx_dashboard) -> - application:set_env(emqx_dashboard, listeners, []), + Options = [{http,{"127.0.0.1",18184}, + [{num_acceptors,4}, + {max_connections,512}, + {inet6,false}, + {ipv6_v6only,false}]}], + application:set_env(emqx_dashboard, listeners, Options), ok; (_) -> ok