如何在 Docker 容器中 运行 时配置 Apache NiFi nifi.web.proxy.host?
How do I configure Apache NiFi nifi.web.proxy.host when running in a Docker container?
我已经使用命令
在容器中成功启动了 Apache NiFi
docker run --name nifi -p 9090:9090 -d -e NIFI_WEB_HTTP_PORT='9090' apache/nifi:latest
并且可以连接到 http://localhost:9090/nifi
上的 UI - 但是,我的公司只允许子网之间的 HTTPS 连接,所以我使用 Nginx 反向代理 https 对 NiFi 容器的调用以下配置:
location /nifi/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi/";
proxy_pass http://mercury-dev:9090/nifi/;
}
location /nifi-docs/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi-docs/";
proxy_pass http://mercury-dev:9090/nifi-docs/;
}
location /nifi-api/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi-api/";
proxy_pass http://mercury-dev:9090/nifi-api/;
}
当我从远程机器浏览到 https://mercury-dev/nifi
时,NiFi UI 开始加载,然后失败。屏幕上的错误显示 An unexpected error has occurred. Please check the logs for additional details.
并且 Chrome 开发者控制台报告:
/nifi-api/access/kerberos:1 Failed to load resource: the server responded with a status of 409 (Conflict)
/nifi-api/access/oidc/exchange:1 Failed to load resource: the server responded with a status of 409 (Conflict)
/nifi-api/flow/about:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
/nifi-api/flow/process-groups/root:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
当我登录容器并查看日志文件时,我看到许多错误提示,例如 ERROR [NiFi Web Server-21] org.apache.nifi.web.util.WebUtils The provided context path [/nifi-api] was not whitelisted
我在 NiFi documentation 中找到了使用 nifi.web.proxy.host
和 nifi.web.proxy.context.path
属性将主机和内容列入白名单的参考资料,但我找不到如何操作的说明。
- 容器内没有可用于编辑属性文件的编辑器(无论如何,这确实是一种糟糕的做法)
- 文档提到通过 UI 上的全局菜单设置它们,但我看不到明显的选项。
- 我也许能够为容器命令行提供环境变量,但找不到任何关于这样做的参考,因此找不到要使用的变量名。
如何设置这些属性,或以其他方式在 HTTPS 代理后面获取此容器 运行?
Docker 容器不会公开您需要为此用例直接修改的所有设置,因此您有几个选项(响应您的编号点)。
(常规)您似乎为多个上下文路径提供了配置,但没有为 根路径 (/
) 提供配置。如文档中所述,NiFi 应用程序内部有许多组件上下文路径,因此将其放在代理后面时,应代理根路径。
- 正确,基础 Docker 图像中没有编辑器。您可以基于此构建自己的图像(使用编辑器或自定义 properties/scripts 来处理这种情况)。
- 您链接到的文档正在讨论授予外部代理中继请求的权限。您可以在 NiFi 中将代理的身份添加为用户,以通过 UI 为其授予权限。这与识别 NiFi 应用程序的代理服务(
nifi.properties
设置)是分开的。无法配置您通过 UI 列出的这两个设置。
- 当前Docker
start.sh
file lists the environment variables accepted by the Docker image at this time. To add more, please submit a PR or open a Jira请求改进。
Koji Kawamura 提供了 example configuration 和您可能感兴趣的反向代理背后的 NiFi 运行 文档。
我只需要在 Apache 反向代理上处理 NiFi 1.11.4 的 /nifi
、/nifi-docs
和 /nifi-api
代理,我不能盲目重定向 /
.您的配置几乎正确。
关键是X-ProxyContextPath
。 NiFi 希望它对应于它的 own 根上下文。在您的情况下应该是 /
(因为后端 NiFi 进程需要 /nifi
、/nifi-api
等)。
如果您尝试从子路径提供服务,比如 /my/fancy/context/nifi
,那么您可以将 X-ProxyContextPath
设置为 /my/fancy/context
以及 nifi.web.proxy.context.path
nifi.properties
变为 /my/fancy/context
。请注意,从 reverse-proxied 子路径提供 NiFi 在 1.11.4 中被破坏并在 1.12.0 NIFI-7758. Finally, even in 1.12.0 there is a lingering bug with LDAP login redirection when serving NiFi from a subpath NIFI-7033.
中得到修复
我已经使用命令
在容器中成功启动了 Apache NiFidocker run --name nifi -p 9090:9090 -d -e NIFI_WEB_HTTP_PORT='9090' apache/nifi:latest
并且可以连接到 http://localhost:9090/nifi
上的 UI - 但是,我的公司只允许子网之间的 HTTPS 连接,所以我使用 Nginx 反向代理 https 对 NiFi 容器的调用以下配置:
location /nifi/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi/";
proxy_pass http://mercury-dev:9090/nifi/;
}
location /nifi-docs/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi-docs/";
proxy_pass http://mercury-dev:9090/nifi-docs/;
}
location /nifi-api/ {
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost "mercury-dev";
proxy_set_header X-ProxyPort "443";
proxy_set_header X-ProxyContextPath "/nifi-api/";
proxy_pass http://mercury-dev:9090/nifi-api/;
}
当我从远程机器浏览到 https://mercury-dev/nifi
时,NiFi UI 开始加载,然后失败。屏幕上的错误显示 An unexpected error has occurred. Please check the logs for additional details.
并且 Chrome 开发者控制台报告:
/nifi-api/access/kerberos:1 Failed to load resource: the server responded with a status of 409 (Conflict)
/nifi-api/access/oidc/exchange:1 Failed to load resource: the server responded with a status of 409 (Conflict)
/nifi-api/flow/about:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
/nifi-api/flow/process-groups/root:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
当我登录容器并查看日志文件时,我看到许多错误提示,例如 ERROR [NiFi Web Server-21] org.apache.nifi.web.util.WebUtils The provided context path [/nifi-api] was not whitelisted
我在 NiFi documentation 中找到了使用 nifi.web.proxy.host
和 nifi.web.proxy.context.path
属性将主机和内容列入白名单的参考资料,但我找不到如何操作的说明。
- 容器内没有可用于编辑属性文件的编辑器(无论如何,这确实是一种糟糕的做法)
- 文档提到通过 UI 上的全局菜单设置它们,但我看不到明显的选项。
- 我也许能够为容器命令行提供环境变量,但找不到任何关于这样做的参考,因此找不到要使用的变量名。
如何设置这些属性,或以其他方式在 HTTPS 代理后面获取此容器 运行?
Docker 容器不会公开您需要为此用例直接修改的所有设置,因此您有几个选项(响应您的编号点)。
(常规)您似乎为多个上下文路径提供了配置,但没有为 根路径 (/
) 提供配置。如文档中所述,NiFi 应用程序内部有许多组件上下文路径,因此将其放在代理后面时,应代理根路径。
- 正确,基础 Docker 图像中没有编辑器。您可以基于此构建自己的图像(使用编辑器或自定义 properties/scripts 来处理这种情况)。
- 您链接到的文档正在讨论授予外部代理中继请求的权限。您可以在 NiFi 中将代理的身份添加为用户,以通过 UI 为其授予权限。这与识别 NiFi 应用程序的代理服务(
nifi.properties
设置)是分开的。无法配置您通过 UI 列出的这两个设置。 - 当前Docker
start.sh
file lists the environment variables accepted by the Docker image at this time. To add more, please submit a PR or open a Jira请求改进。
Koji Kawamura 提供了 example configuration 和您可能感兴趣的反向代理背后的 NiFi 运行 文档。
我只需要在 Apache 反向代理上处理 NiFi 1.11.4 的 /nifi
、/nifi-docs
和 /nifi-api
代理,我不能盲目重定向 /
.您的配置几乎正确。
关键是X-ProxyContextPath
。 NiFi 希望它对应于它的 own 根上下文。在您的情况下应该是 /
(因为后端 NiFi 进程需要 /nifi
、/nifi-api
等)。
如果您尝试从子路径提供服务,比如 /my/fancy/context/nifi
,那么您可以将 X-ProxyContextPath
设置为 /my/fancy/context
以及 nifi.web.proxy.context.path
nifi.properties
变为 /my/fancy/context
。请注意,从 reverse-proxied 子路径提供 NiFi 在 1.11.4 中被破坏并在 1.12.0 NIFI-7758. Finally, even in 1.12.0 there is a lingering bug with LDAP login redirection when serving NiFi from a subpath NIFI-7033.