首页 > 解决方案 > 如何使用 Waitress 和 Nginx 服务本地应用程序

问题描述

我有一个使用flask作为服务器设置的dash(plotly)应用程序,可以在我们的Windows Server上使用服务员将其提供到端口:8041。我启动女服务员的代码如下;

#!/usr/bin/env python3

from waitress import serve
from src.pacedash.app import server as application

if __name__ == "__main__":
    serve(application, threads=100, port=8041)

如果我使用 python run_waitress.py,一切都很好,除了当我们网络上的某人导航到 servename:8041 时,url 旁边会出现“不安全”警告。我们的 IT 供应商能够获得证书文件和密钥,但我不确定如何将它们带入我当前的设置中。

我一直在尝试使用 nginx,但我找不到使用服务员设置它的指南,而且我对 Web 应用程序或 wsgi 不太熟悉,因为我主要在这里作为唯一的数据人员工作。

标签: pythonnginxwindows-server-2008plotly-dashwaitress

解决方案


我一直在研究同样的问题并有解决方案。nginx .conf 文件需要有一个如下定义的位置:

location /myapp/ {
       # Define the location of the proxy server to send the request to
       proxy_pass http://localhost:8041/myapp/;

       # standard proxy_set_header stuff below...
}

然后在您的 Dash 应用程序中将 url_base_pathname 设置为相同的值:

app = dash.Dash(__name__, url_base_pathname='/myapp/') 

推荐阅读