簡體   English   中英

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

[英]Deploying Dash app on Apache using mod_wsgi

我正在嘗試使用 Apache 和 mod_wsgi 托管一個簡單的破折號應用程序作為測試。 但是,該頁面未加載,並且似乎陷入了重定向循環。

此 Flask 部署教程已遵循: https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/

遵循此 mod_wsgi 配置教程,簡單的 WSGI 應用程序按預期工作: https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html

用破折號文件替換簡單的 WSGI 應用程序時會出現問題。 dash 應用程序在本地按預期運行。 沒有錯誤消息,頁面只是沒有加載。

這是 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

from test import server as application

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)

如此所述,請嘗試以下操作:

  1. 如有必要,添加requests_pathname_prefix參數。

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

  1. 不要重新分配服務器變量。 相反,您的 test2.wsgi 文件應如下所示:

    from test import app application = app.server

經過一番掙扎,這最終對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM