【发布时间】:2022-11-10 12:29:55
【问题描述】:
我正在尝试在可使用公共 IP(在 NAT 后面)访问的 VM 上运行 Dash 应用程序。
这是基本的 Dash 应用程序:
from dash import Dash, html
import dash_bootstrap_components as dbc
import dash_daq as daq
from dash import Input, Output, State, dcc
from flask import Flask, url_for
import os
import numpy as np
server = Flask(__name__)
server.config.update(
SERVER_NAME=os.getenv("SERVER_NAME", "localhost:8080")
)
app = Dash(__name__,server=server, external_stylesheets=[dbc.themes.BOOTSTRAP, \
dbc.icons.BOOTSTRAP])
app.layout = html.Div(children=[ html.H1(children='Test'), html.Div( '\
'' Built with Dash: A web application framework for Python. ''')])
if __name__ == '__main__':
app.run_server(debug=True,host='0.0.0.0',port=8080)
如果我使用python test.py 运行应用程序,当我浏览 http://my_public_IP:8080 时,它会返回:werkzeug.exceptions.NotFound: 404 Not Found
如果我使用gunicorn --workers 1 --bind 0.0.0.0:8080 test:server 运行应用程序,它会返回经典:
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
以下日志由 gunicorn 生成:
[2022-09-20 09:25:50 +0000] [62184] [INFO] Starting gunicorn 20.1.0
[2022-09-20 09:25:50 +0000] [62184] [INFO] Listening at: http://0.0.0.0:8080 (62184)
[2022-09-20 09:25:50 +0000] [62184] [INFO] Using worker: sync
[2022-09-20 09:25:50 +0000] [62186] [INFO] Booting worker with pid: 62186
/home/azure-vm-user/.local/lib/python3.8/site-packages/flask/app.py:2218: UserWarning: Current server name 'my_public_IP:8080' doesn't match configured server name 'localhost:8080'
return self.url_map.bind_to_environ(
谢谢你的帮助。我可能在这里遗漏了一些简单的东西,但在 SO 中找不到任何等效的东西,除了这篇没有解决我的问题的帖子: Not able to deploy dash application on gunicorn
【问题讨论】:
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。