本文介绍了部署在Apache2系统上的Dash应用程序永远不会让用户过去“正在加载...",因为它似乎找不到其破折号.js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Apache2服务器和 mod_wsgi 服务(python3.8.2) dash 应用程序,但是该应用程序会在正在加载..."屏幕.服务器为每个破折号.js脚本返回404.使用dash的内置本地服务器时,我没有任何问题...但是我没有尝试在本地提供此服务.

I am trying serve a (python3.8.2) dash application using an Apache2 server and mod_wsgi, but the application stops on the "Loading..." screen. The server returns 404s for each of dash's .js scripts. I've had no problems when using dash's built in local server... but I'm not trying to serve this locally.

我很想知道我要去哪里,以及如何启动并运行此特定应用.

I'd love some advice on where I'm going wrong, and how to get this particular app up and running.

我可以同时使用简单的python"hello world"和一个简单的烧瓶应用程序,使用我的设置但是,当创建一个简单的破折号"应用程序时...

I am able to serve both a simple python "hello world" and a simple flask app, using my setup. However, when creating a simple 'dash' app...

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (polyfill@7.v1_6_0m1598005008.8.7.min.js, line 0)
... followed by 12 more similar error messages...
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (dash_renderer.v1_6_0m1598005008.min.js, line 0)
[Error] ReferenceError: Can't find variable: DashRenderer
    Global Code (hazcurves:28:103)

我的apache访问日志显示了一系列获得404的GET请求(这是一个示例):

my apache access log shows a series of GET requests that got 404's (here's one example):

... "GET /_dash-component-suites/dash_renderer/dash_renderer.v1_6_0m1598005008.min.js HTTP/1.1" 404 495 "http://efehr-dev.ethz.ch/hazcurves/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15"

其他观察结果

当我比较正常运行的Dash应用程序中提供的html与html时,发现.js名称有所不同.看来我的东西正以某种方式被破坏.

Additional observations

When I compared my served html to the html from a correctly functioning Dash app, I notice a difference in the .js names. It looks like mine are being mangled somehow.

功能版本,来自 https://dash-gallery.plotly.host/dash-wind-streaming/

# Excerpt from functioning app's "footer" section
<footer>
  <script id="_dash-config" type="application/json">{"url_base_pathname": null, "requests_pathname_prefix": "/dash-wind-streaming/", "ui": false, "props_check": false, "show_undo_redo": false}</script>

  # [CGR] then there are  several components here that are variations of the following
  <script src="/dash-wind-streaming/_dash-component-suites/dash_renderer/dash_renderer.min.js?v=1.0.0&m=1583853516"></script>

  <script id="_dash-renderer" type="application/javascript">
        var renderer = new DashRenderer();
        </script>

我的应用程序的页脚使请求看起来很混乱,查询参数已吸收到文件名中.

My app's Footer makes the request look scrambled, with query parameters absorbed into the filename.

<footer>
  <script id="_dash-config" type="application/json">{"url_base_pathname": null, "requests_pathname_prefix": "/", "ui": false, "props_check": false, "show_undo_redo": false, "suppress_callback_exceptions": false, "update_title": "Updating..."}</script>

  # [CGR] then there are  several components here that are variations of the following
  <script src="/_dash-component-suites/dash_html_components/dash_html_components.v1_0_3m1598005008.min.js"></script>
  <script src="/_dash-component-suites/dash_renderer/dash_renderer.v1_6_0m1598005008.min.js"></script>
  <script id="_dash-renderer" type="application/javascript">var renderer = new DashRenderer();</script>
        </footer>

现在,这些.js文件(未加密的版本)确实存在,并且 _dash-component-suites 似乎映射到了我的 .local/lib/python3.8/site-包文件夹.

Now, these .js files [the unscrambled versions] DO exist, and _dash-component-suites would seem to map to my .local/lib/python3.8/site-packages folder.

因此,从上面显示的内容来看,我有 .../dash_renderer/dash_renderer.min.js .../dash_html_components.min.js

So, from what I've shown above, I have .../dash_renderer/dash_renderer.min.js and .../dash_html_components.min.js

一个带有Ubuntu 20.04.1 LTS的干净系统,安装了mod_wsgi的Apache 2.4.
Python 3.8.2安装了以下相关软件包(使用sudo pip3):

A clean system with Ubuntu 20.04.1 LTS , Apache 2.4 with mod_wsgi installed.
Python 3.8.2 has the following relevant packages installed [using sudo pip3] :

dash==1.14.0
dash-core-components==1.10.2
dash-html-components==1.0.3
dash-renderer==1.6.0
dash-table==4.9.0
Flask==1.1.2
Flask-Compres=1.5.0

这是我的app.wsgi:

Here is my app.wsgi:

from flask import Flask
server = Flask(__name__)

import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(server=server)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
app.layout = html.Div(children=["hello"])
application = app.server

我已经能够使用内置服务器在本地服务器上运行它.

I have been able to run this using the built-in server, serving it on a local server.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /home/username/public_html

        WSGIDaemonProcess /home/username/public_html/myapp.wsgi processes=2 threads=15 display-name=%{GROUP}
        WSGIScriptAlias /hazcurves /home/username/public_html/myapp.wsgi

        <Directory /home/username/public_html>
                AllowOverride all
                Options Indexes FollowSymLinks
                <Limit GET POST OPTIONS>
                        Require all granted
                </Limit>
        </Directory>


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我愿意尝试的一些事情

  • 烧瓶中的Hello world:效果很好
  • Dash中的Hello world:失败
  • 在服务器配置中创建别名 alias _dash-component-suites/.local/lib/python3.8/site-packages
  • 更改request_pathnames_prefix:似乎没有任何效果,也不显示在html输出中.那给了我403,而不是404.但是后来我也注意到了名称的不一致.
  • app.css.config.serve_locally = True#也尝试过False:没有明显的作用
  • app.scripts.config.serve_locally = True#也尝试过False:没有明显的作用
  • 尝试从与该问题相关的网站上寻求建议后,我开始感觉像猴子在敲键---感觉错误(而且不安全)

    After attempting to shoehorn advice from websites that are tangentially relevant towards this question, I'm starting to feel like a monkey banging on keys --- which feels, um wrong (and insecure)

    最终警告:这是我第一次尝试在世界服务器端管理应用程序.

    final caveat: this is my first foray into managing an app on the server side of the world.

    推荐答案

    我很高兴地报告我最终解决了这个问题,并且我的应用程序现在运行良好.这就是我学到的东西.

    I am happy to report I eventually figured it out, and that my applications are running great now. Here's what I learned.

    在调用 dash.Dash(...)时,我必须谨记以下几点:我需要写的不是我写的东西:

    I had to be mindful of the following when calling dash.Dash(...) Instead of what I had written, I needed:

    dash.Dash(__name__, requests_pathname_prefix='/hazcurves/')
    

    重要的教训如下:

    1. 请勿覆盖服务器变量.我不知何故失去了自己创建的任何配置.
    2. 需要与URL别名匹配的
    3. requests_pathname_prefix (以斜杠结束).
    1. Do not overwrite the server variable. Somehow I was loosing any configurations I had created.
    2. requests_pathname_prefix needed to match the URL alias (starting end ending with slashes).

    红鲱鱼(实际上无关紧要的东西):

    1. 首先创建Flask实例
    2. 关于本地服务的
    3. 配置
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    

    因此,以下是我感兴趣的三个文件的摘录:

    So, here are excerpts from my three files of interest:

    mysite.conf :/etc/apache2/sites-available/mysite.conf

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /home/myusername/public_html
    
    
        # ---- Hazard Curves App ---- #
        # using WSGIProcessGroup within Location allows multiple apps to run
        # without interfering with each other
    
        WSGIDaemonProcess curves/wsgi.py processes=2 threads=15 display-name=%{GROUP}
        WSGIScriptAlias /curves /home/myusername/public_html/curves/wsgi.py
        <Location /curves>
            WSGIProcessGroup curves/wsgi.py
        </Location>
    </VirtualHost>
    

    wsgi.py :〜/public_html/curves/wsgi.py

    #!/usr/bin/python3
    
    from myapp import app
    application = app.server
    

    myapp.py :〜/public_html/curves/myapp.py

    import dash
    import dash_html_components as html
    
    app = dash.Dash(__name__, requests_pathname_prefix='/curves/')
    
    app.title = "Some Test"
    app.layout = html.Div([html.H6("Hello World")])
    
    if __name__ == '__main__':
        app.run_server(port=8051, debug=True) # unimportant in this context
    

    这篇关于部署在Apache2系统上的Dash应用程序永远不会让用户过去“正在加载...",因为它似乎找不到其破折号.js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:00
查看更多