首页 > 解决方案 > 在 apache2 服务器上使用一个配置文件部署多个破折号应用程序时出现问题

问题描述

我们正在尝试通过使用相同的配置文件但不同的 wsgi 文件来部署多个 dash 应用程序。现在这就是我们所拥有的,当我们运行它时,页面显示“错误加载”布局。

我们的配置文件和 wsgi 文件如下所示:

配置文件:

WSGIPythonPath /var/www/test/test1:/var/www/test/test2

<VirtualHost *:8084>
    ServerName <example ip>
    ServerAdmin youremail@mail.com

    WSGIScriptAlias /test1 /var/www/test/wsgi-files/test1.wsgi
    <Directory /var/www/test/test1/>
            Require all granted
    </Directory>

    Alias /test1/static /var/www/test/test1/static
    <Directory /var/www/test/test1/static/>
            Require all granted
    </Directory>

    WSGIScriptAlias /test2 /var/www/test/wsgi-files/test2.wsgi
    <Directory /var/www/test/test2/>
            Require all granted
    </Directory>

    Alias /test2/static /var/www/test/test2/static
    <Directory //var/www/test/test2/static/>
            Require all granted
    </Directory>

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

Wsgi 文件:

#!/usr/bin/python2.7
import sys
import logging
sys.stdout = sys.stderr
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/test/")

from test1 import server as application

第二个 wsgi 文件看起来像上面的文件,但指向 test2。

我们使用来自 dash 的简单测试代码作为示例,我们希望在 example.com/test1 找到第一个测试应用程序,在 example.com/test2 找到第二个应用程序。

在 WSGIScriptAlias 中,如果我们写“/ /var/www/test/wsgi-files/test1.wsgi”而不是“/test1 /var/www/test/wsgi-files/test1.wsgi”,我们不会得到错误但 test1-应用程序将出现在我们正在部署的端口的每个页面上。我们对 dash、python 和 web 开发还很陌生,所以可能是一个简单的答案,但我们花了最后几个小时尝试我们能找到的每个示例。除此之外,这是我们尝试过的:https ://www.digitalocean.com/community/questions/running-mutliple-flask-application 。

我们正在使用的应用程序代码如下所示。

import dash
import dash_core_components as dcc
import dash_html_components as html
from flask import Flask

print('Hello this is monkey')
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

server=Flask(__name__)
app = dash.Dash(__name__, server=server,external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    html.H1(children='Test 1'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'Montreal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
server=app.server
@server.route("/test1")
def MyDashApp():
        return app.index()

if __name__ == '__main__':
    app.run_server(debug=True)

我们将非常感谢任何帮助。

标签: flaskapache2configuration-filesplotly-dash

解决方案


推荐阅读