diff --git a/apps/emqx_management/priv/emqx_management.schema b/apps/emqx_management/priv/emqx_management.schema index 0b91509f1..42f63b7bf 100644 --- a/apps/emqx_management/priv/emqx_management.schema +++ b/apps/emqx_management/priv/emqx_management.schema @@ -90,6 +90,11 @@ {datatype, {enum, [true, false]}} ]}. +{mapping, "management.listener.http.proxy_header", "emqx_management.listeners", [ + {default, false}, + {datatype, {enum, [true, false]}} +]}. + {mapping, "management.listener.https", "emqx_management.listeners", [ {datatype, [integer, ip]} ]}. @@ -186,6 +191,11 @@ {datatype, {enum, [true, false]}} ]}. +{mapping, "management.listener.https.proxy_header", "emqx_management.listeners", [ + {default, false}, + {datatype, {enum, [true, false]}} +]}. + {translation, "emqx_management.application", fun(Conf) -> Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, Opts = fun(Prefix) -> @@ -202,7 +212,9 @@ end}. Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, Opts = fun(Prefix) -> Filter([{num_acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)}, - {max_connections, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)}]) + {max_connections, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)}, + {proxy_header, cuttlefish:conf_get(Prefix ++ ".proxy_header", Conf)} + ]) end, TcpOpts = fun(Prefix) -> Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)}, diff --git a/apps/emqx_management/src/emqx_management.app.src b/apps/emqx_management/src/emqx_management.app.src index fe927c097..b505e2c69 100644 --- a/apps/emqx_management/src/emqx_management.app.src +++ b/apps/emqx_management/src/emqx_management.app.src @@ -1,6 +1,6 @@ {application, emqx_management, [{description, "EMQ X Management API and CLI"}, - {vsn, "4.4.12"}, % strict semver, bump manually! + {vsn, "4.4.13"}, % strict semver, bump manually! {modules, []}, {registered, [emqx_management_sup]}, {applications, [kernel,stdlib,emqx_plugin_libs,minirest]}, diff --git a/apps/emqx_management/src/emqx_mgmt_http.erl b/apps/emqx_management/src/emqx_mgmt_http.erl index 444e0ce25..7f571ee70 100644 --- a/apps/emqx_management/src/emqx_mgmt_http.erl +++ b/apps/emqx_management/src/emqx_mgmt_http.erl @@ -52,12 +52,12 @@ stop_listeners() -> start_listener({Proto, Port, Options}) when Proto == http -> Dispatch = [{"/status", emqx_mgmt_http, []}, {"/api/v4/[...]", minirest, http_handlers()}], - minirest:start_http(listener_name(Proto), ranch_opts(Port, Options), Dispatch); + minirest:start_http(listener_name(Proto), ranch_opts(Port, Options), Dispatch, proto_opts(Options)); start_listener({Proto, Port, Options}) when Proto == https -> Dispatch = [{"/status", emqx_mgmt_http, []}, {"/api/v4/[...]", minirest, http_handlers()}], - minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch). + minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch, proto_opts(Options)). ranch_opts(Port, Options0) -> NumAcceptors = proplists:get_value(num_acceptors, Options0, 4), @@ -68,6 +68,7 @@ ranch_opts(Port, Options0) -> ({inet6, false}, Acc) -> Acc; ({ipv6_v6only, true}, Acc) -> [{ipv6_v6only, true} | Acc]; ({ipv6_v6only, false}, Acc) -> Acc; + ({proxy_header, _}, Acc) -> Acc; ({K, V}, Acc)-> [{K, V} | Acc] end, [], Options0), @@ -77,6 +78,9 @@ ranch_opts(Port, Options0) -> socket_opts => [{port, Port} | Options]}, Res. +proto_opts(Options) -> + maps:with([proxy_header], maps:from_list(Options)). + stop_listener({Proto, Port, _}) -> io:format("Stop http:management listener on ~s successfully.~n",[format(Port)]), minirest:stop_http(listener_name(Proto)). diff --git a/rebar.config b/rebar.config index 695a3a0cf..d839d7404 100644 --- a/rebar.config +++ b/rebar.config @@ -51,7 +51,7 @@ , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.8.1.11"}}} , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.0.1"}}} , {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}} - , {minirest, {git, "https://github.com/emqx/minirest", {tag, "0.3.10"}}} + , {minirest, {git, "https://github.com/emqx/minirest", {tag, "0.3.11"}}} , {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.2"}}} , {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.4"}}} , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}}