简体   繁体   English

使用 mod_wsgi 在 Apache 上部署 Dash 应用程序

[英]Deploying Dash app on Apache using mod_wsgi

I am trying host a simple dash application as a test using Apache and mod_wsgi.我正在尝试使用 Apache 和 mod_wsgi 托管一个简单的破折号应用程序作为测试。 However, the page isn't loading and seems to be stuck in a loop of redirects.但是,该页面未加载,并且似乎陷入了重定向循环。

This Flask deployment tutorial has been followed: https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/此 Flask 部署教程已遵循: https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/

This mod_wsgi configuration tutorial has been followed and the simple WSGI application works as expected: https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html遵循此 mod_wsgi 配置教程,简单的 WSGI 应用程序按预期工作: https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html

The issue arises when replacing the simple WSGI application with the dash files.用破折号文件替换简单的 WSGI 应用程序时会出现问题。 The dash application runs as expected locally. dash 应用程序在本地按预期运行。 There are no error messages, the page just doesn't load.没有错误消息,页面只是没有加载。

This is the apache config file:这是 apache 配置文件:

WSGIDaemonProcess dash socket-user=aroth user=aroth group=apache threads=5 home=/home/aroth/public_html/test2/ python-path=/home/aroth/.local/lib/python3.6/site-packages
    WSGIScriptAlias /dash/aroth/test2/ /home/aroth/public_html/test2/test2.wsgi
 
    <Directory /home/aroth/public_html/test2>
      AssignUserID aroth apache
      WSGIProcessGroup dash
      WSGIApplicationGroup %{GLOBAL}
      Options FollowSymLinks Indexes
      Require all granted
    </Directory>

test2.wsgi test2.wsgi

from test import server as application

test.py (this is an example dash application taken from here http://dash-docs.herokuapp.com/deployment ) test.py(这是一个示例 dash 应用程序,取自这里http://dash-docs.herokuapp.com/deployment

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

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

server = app.server

app.layout = html.Div([
    html.H2('Hello World'),
    dcc.Dropdown(
        id='dropdown',
        options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
        value='LA'
    ),
    html.Div(id='display-value')
])

@app.callback(dash.dependencies.Output('display-value', 'children'),
              [dash.dependencies.Input('dropdown', 'value')])
def display_value(value):
    return 'You have selected "{}"'.format(value)

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

As stated here , try the following:如此所述,请尝试以下操作:

  1. Add the requests_pathname_prefix parameter if necessary.如有必要,添加requests_pathname_prefix参数。

app = dash.Dash(__name__, external_stylesheets=external_stylesheets, requests_pathname_prefix='/hello/')

  1. Do NOT reassign the server variable.不要重新分配服务器变量。 Instead, your test2.wsgi file should look as follows:相反,您的 test2.wsgi 文件应如下所示:

    from test import app application = app.server

After quite some struggle, this eventually did the trick for me.经过一番挣扎,这最终对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM