【问题标题】:Running Apache NiFi behind Nginx在 Nginx 后面运行 Apache NiFi
【发布时间】:2019-02-28 22:58:21
【问题描述】:

我正在尝试使用 nginx 作为反向代理来连接到 nifi。 我正在使用以下流程: 本地机器 -> http -> NGINX -> https -> Secure NiFi

以下是我的 nifi.properties 配置:

nifi.web.https.host=localhost
 nifi.web.https.port=8443
 nifi.web.https.network.interface.default=
 nifi.web.jetty.working.directory=./work/jetty
 nifi.web.jetty.threads=200
 nifi.web.max.header.size=16 KB
 nifi.web.proxy.context.path=/nifi/
 nifi.web.proxy.host=localhost:8443
 nifi.remote.input.host=localhost
 nifi.remote.input.secure=true

下面是我的nginx配置:

 server {
         listen       81;
         server_name  localhost;
     location /nifi/ {

        proxy_ssl_certificate     C:/nifi-toolkit-1.7.1/target/nifi-cert.pem;
        proxy_ssl_certificate_key C:/nifi-toolkit-1.7.1/target/nifi-key.key;
        proxy_ssl_server_name on;

        proxy_pass https://localhost:8443;
        proxy_set_header X-ProxyScheme "https";
        proxy_set_header X-ProxyHost $http_host;
        proxy_set_header X-ProxyPort 8443;
        proxy_set_header X-ProxyContextPath "";
        root   html;
        index  index.html index.htm;
    }

    location /nifi-api/{

        proxy_ssl_certificate     C:/nifi-toolkit-1.7.1/target/nifi-cert.pem;
        proxy_ssl_certificate_key C:/nifi-toolkit-1.7.1/target/nifi-key.key;
        proxy_ssl_server_name on;

        proxy_set_header X-ProxyScheme "https";
        proxy_set_header X-ProxyHost $http_host;
        proxy_set_header X-ProxyPort 443;
        proxy_set_header X-ProxyContextPath "";
        proxy_pass https://localhost:8443/nifi-api/;
 }
}

当我尝试通过 nginx 访问 nifi 时,我在 error.logs 中收到以下错误:

2018/09/25 15:41:55 [error] 100964#77892: *27 upstream timed out (10060: A `connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "POST /nifi-api/access/oidc/exchange HTTP/1.1", upstream: "https://[::1]:8443/nifi-api/access/oidc/exchange", host: "localhost:81", referrer: "http://localhost:81/nifi/"`

以下是我在点击 url 时在浏览器中遇到的错误:http://localhost:81/nifi/

我是否缺少任何配置设置。任何帮助将不胜感激。

提前谢谢你。

【问题讨论】:

  • 可以不通过代理访问 NiFi 吗?也就是说,当您尝试访问 https://localhost:8443/nifi 并提供客户端证书时会发生什么?
  • 嗨@kevdoran,很抱歉这么晚才回复。是的,我无需通过 nifi 即可访问上述网址。它工作正常。当我尝试通过 nginx 访问 nifi 时出现问题。 Http 在 nginx 中被阻止。当我尝试访问任何处理器时,我收到以下错误
  • jquery.min.js:4 混合内容:“something.com/nifi/nifi/…”处的页面通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“something.com/nifi/nifi-api/process-groups/…”。此请求已被阻止;内容必须通过 HTTPS 提供。

标签: nginx apache-nifi nginx-reverse-proxy


【解决方案1】:

问题是 nifi.web.proxy.context.path 设置不正确。

查看文档:

https://docs.hortonworks.com/HDPDocuments/HDF3/HDF-3.3.0/nifi-configuration-best-practices/content/proxy_configuration.html

NiFi 将只接受带有 X-ProxyContextPath 或 X-Forwarded-Context 标头,如果该值在 nifi.properties 中的 nifi.web.proxy.context.path 属性。这个性质 接受以逗号分隔的期望值列表。在事件中 传入请求具有 X-ProxyContextPath 或 X-Forwarded-Context 白名单中不存在的标头值,“意外 发生错误”页面将显示并写入错误 nifi-app.log。

【讨论】:

    【解决方案2】:

    正如 echo 指出的那样,您的 X-ProxyContextPath 应该与您的位置相同,并且您的 nifi.web.proxy.context.path= 在 nifi.properties 中也应该相同。

    在尝试在混合中引入 SSL 之前,我喜欢使用简单的 HTTP 身份验证来运行。

    客户端>http请求>NGINX反向代理>http请求>NIFI

    在这种情况下,您的 NIFI 配置文件“nifi.properties”应如下所示:

     nifi.web.https.host=
     nifi.web.https.port=
     nifi.web.proxy.context.path=/
     nifi.web.proxy.host=localhost:80
     nifi.remote.input.host=localhost
     nifi.remote.input.secure=false
    

    重启 NIFI。

    注意上下文路径是 / only,所以这就是根目录下的所有内容。

    对于 NGINX

    server {
             listen       80;
             server_name  localhost;
         location / {
    
            proxy_pass https://YOUR_NIFI_INSTANCE:8080;
            proxy_set_header X-ProxyScheme "http";
            proxy_set_header X-ProxyHost localhost;
            proxy_set_header X-ProxyPort 80;
            proxy_set_header X-ProxyContextPath "/";
        }
    }
    

    用你的 NIFI 盒子的 url 更新 YOUR_NIFI_INSTANCE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-02
      • 2020-06-29
      • 2011-10-24
      • 1970-01-01
      • 2019-07-12
      • 2020-05-28
      • 1970-01-01
      • 2016-02-22
      相关资源
      最近更新 更多