无法从 Nginx 后面的 dash 应用 运行 加载 _dash-layout 和 _dash-dependencies
Unable to load _dash-layout and _dash-dependencies from dash app running behind Nginx
我在使用蓝图注册路线的 Flask 应用程序中提供破折号内容。
应用设置:
- Dash 初始化为
route_pathname_prefix=/dashapp/
dash_app = dash.Dash(
server=server,
routes_pathname_prefix='/dashapp/',
)
dash_app.css.config.serve_locally = True
dash_app.scripts.config.serve_locally = True
- 使用 Flask 服务器注册 dash 应用程序
- 使用 UWSGI 在 docker 容器中为 Flask 应用提供服务
[uwsgi]
wsgi-file = </path/to/app.py>
callable = app
http = 0.0.0.0:8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
到目前为止,本地一切正常。添加 Nginx 代理后,出现以下问题
问题:
_dash-layout
和 _dash-dependencies
的 urls 缺少反向代理 uri。例如,我在 www.example.com/app/
提供我的烧瓶应用程序。但是,在浏览器上,我看到 _dash-layout
和 _dash-dependencies
的请求来自 www.example.com/dashpp/_dash-layout
而不是 www.example.com/app/dashpp/_dash-layout
。
我阅读了以下论坛 discussion 并尝试应用该解决方案,但遇到了这个错误,
requests_pathname_prefix
需要以 '/' 开头`
这是我的 Nginx 配置,
location /app/ {
proxy_pass http://localhost:<port>;
proxy_redirect http://localhost:<port> http://example.com/app/;
proxy_set_header Accept Encoding "";
sub_filter_types *;
sub_filter 'href="/' 'href="/app/';
sub_filter 'src="/' 'src="/app/';
sub_filter_once off;
}
任何人都可以指出缺少的内容。我是新手。所以,如果我错过了添加任何信息,请告诉我,我很乐意提供更多详细信息
谢谢
PS: 我在破折号 forum 中添加了同样的问题。将它张贴在这里以获得更好的影响。
编辑:
为了添加额外的上下文,我发现 _dash-component-suites
的 url 是按预期生成的 www.example.com/app/dashpp/_dash-component-suites
。我浏览了破折号源代码以了解 urls 是如何生成的。 _dash-component-suites
和 _dash-layout
都以 routes_pathname_prefix
为前缀。 1.14.0版本dash.py的第428到448行有构建urls.
的代码
这令人困惑!!!
我能够通过从 nginx conf 中删除 sub_filter
指令并在 flask 应用程序中更新 url_prefixes 来解决这个问题。我采取的步骤发布在 this dash 论坛
我在使用蓝图注册路线的 Flask 应用程序中提供破折号内容。 应用设置:
- Dash 初始化为
route_pathname_prefix=/dashapp/
dash_app = dash.Dash(
server=server,
routes_pathname_prefix='/dashapp/',
)
dash_app.css.config.serve_locally = True
dash_app.scripts.config.serve_locally = True
- 使用 Flask 服务器注册 dash 应用程序
- 使用 UWSGI 在 docker 容器中为 Flask 应用提供服务
[uwsgi]
wsgi-file = </path/to/app.py>
callable = app
http = 0.0.0.0:8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
到目前为止,本地一切正常。添加 Nginx 代理后,出现以下问题
问题:
_dash-layout
和 _dash-dependencies
的 urls 缺少反向代理 uri。例如,我在 www.example.com/app/
提供我的烧瓶应用程序。但是,在浏览器上,我看到 _dash-layout
和 _dash-dependencies
的请求来自 www.example.com/dashpp/_dash-layout
而不是 www.example.com/app/dashpp/_dash-layout
。
我阅读了以下论坛 discussion 并尝试应用该解决方案,但遇到了这个错误,
requests_pathname_prefix
需要以 '/' 开头`
这是我的 Nginx 配置,
location /app/ {
proxy_pass http://localhost:<port>;
proxy_redirect http://localhost:<port> http://example.com/app/;
proxy_set_header Accept Encoding "";
sub_filter_types *;
sub_filter 'href="/' 'href="/app/';
sub_filter 'src="/' 'src="/app/';
sub_filter_once off;
}
任何人都可以指出缺少的内容。我是新手。所以,如果我错过了添加任何信息,请告诉我,我很乐意提供更多详细信息
谢谢
PS: 我在破折号 forum 中添加了同样的问题。将它张贴在这里以获得更好的影响。
编辑:
为了添加额外的上下文,我发现 _dash-component-suites
的 url 是按预期生成的 www.example.com/app/dashpp/_dash-component-suites
。我浏览了破折号源代码以了解 urls 是如何生成的。 _dash-component-suites
和 _dash-layout
都以 routes_pathname_prefix
为前缀。 1.14.0版本dash.py的第428到448行有构建urls.
这令人困惑!!!
我能够通过从 nginx conf 中删除 sub_filter
指令并在 flask 应用程序中更新 url_prefixes 来解决这个问题。我采取的步骤发布在 this dash 论坛