使用ProxyFix在反向代理后面运行气流

2024-09-30 20:31:27 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

[webserver]
enable_proxy_fix = True

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

^{pr2}$

然后运行以下命令:

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头而不是{}头,但由于某些原因,它没有使用。在

你知道我缺少什么配置吗?在


Tags: tocomlocalhosthttphosthtmlcontentcurl
1条回答
网友
1楼 · 发布于 2024-09-30 20:31:27

找到了根本原因,这与不同的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不提供现成的钩子来设置此属性,因此Airflow的ProxyFix不能与werkzeug 0.15.x一起使用。在

0.14.x默认情况下信任第一个标头,但它与flask>;=1.10不兼容,后者气流使用:

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

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

相关问题 更多 >