【问题标题】:Running airflow behind a reverse proxy with ProxyFix使用 ProxyFix 在反向代理后面运行气流
【发布时间】:2019-08-16 21:57:36
【问题描述】:

尝试设置气流以在反向代理后面运行,如下所述: https://airflow.readthedocs.io/en/stable/howto/run-behind-proxy.html

我正在运行气流 v1.10.3 并启用了 ProxyFix:

[webserver]
enable_proxy_fix = True

在网络服务器日志中确认它已正确启动:

/usr/local/lib/python3.6/site-packages/airflow/www_rbac/app.py:48: DeprecationWarning: 'werkzeug.contrib.fixers.ProxyFix' has moved to 'werkzeug.middleware.proxy_fix.ProxyFix'. This import is deprecated as of version 0.15 and will be removed in 1.0.

然后运行以下内容:

curl http://localhost:8080 --header "X-Forwarded-Host: airflow.staging.spothero.com" -v
* Rebuilt URL to: http://localhost:8080/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> X-Forwarded-Host: airflow.staging.spothero.com
> 
< HTTP/1.1 302 FOUND
< Server: gunicorn/19.9.0
< Date: Fri, 16 Aug 2019 17:14:54 GMT
< Connection: close
< Content-Type: text/html; charset=utf-8
< Content-Length: 217
< Location: http://localhost:8080/home```
curl http://localhost:8080 --header "Host: airflow.staging.spothero.com" -v
* Rebuilt URL to: http://localhost:8080/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: airflow.staging.spothero.com
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 302 FOUND
< Server: gunicorn/19.9.0
< Date: Fri, 16 Aug 2019 17:21:27 GMT
< Connection: close
< Content-Type: text/html; charset=utf-8
< Content-Length: 217
< Location: http://airflow.staging.spothero.com/home

您可以看到使用Host 标头正确生成重定向,但使用X-Forwarded-Host 标头错误生成。 ProxyFix 应该在生成这些重定向时使用 X-Forwarded-Host 标头而不是 Host 标头,但由于某种原因它不是。

关于我在这里缺少什么配置的任何想法?

【问题讨论】:

    标签: python proxy reverse-proxy airflow werkzeug


    【解决方案1】:

    找到根本原因,它与不同的 werkzeug 版本有关(我运行的是 0.15.x 而不是 0.14.x)。

    https://werkzeug.palletsprojects.com/en/0.14.x/contrib/fixers/ https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix

    默认情况下,0.15.x 版本需要设置 x_host=1 以信任第一个 X-Forwarded-Host 标头,否则 ProxyFix 将完全忽略标头。 Airflow 不提供开箱即用设置此属性的挂钩,因此气流的 ProxyFix 不适用于 werkzeug 0.15.x

    0.14.x 默认信任第一个标头,但它与气流使用的烧瓶 >=1.10 不兼容:

    https://issues.apache.org/jira/browse/AIRFLOW-4900

    这已在气流 1.10.4 中修复: https://github.com/apache/airflow/pull/5563

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2021-08-30
      • 2018-03-12
      • 1970-01-01
      • 2011-11-10
      相关资源
      最近更新 更多