python - 无法使用 nginx 和 uwsgi 在服务器上运行 dash 应用程序
问题描述
Ubuntu 18.04
我尝试按照本教程使用 nginx 和 uwsgi 在服务器上运行 dash 应用程序:https ://levelup.gitconnected.com/the-easiest-way-to-host-a-multi-page-dashboard-using-python-dash -and-linux-for-beginners-78a78e821ba
文件夹结构:
/
---- etc/nginx...
---- root
---- DashApp
---- index.py
---- wsgi.py
---- index.ini
我的仪表板应用程序如下所示:
/root/DashApp/index.py:
app = dash.Dash(__name__)
app.layout = html.Div([
html.H4('Hello, world!'),
dcc.Graph(id='my-graph')])
#further several callbacks functions like this
@app.callback(Output('my-graph', 'figure'),
[Input('df_values', 'children')])
def update_graph(value):
return px.line(....)
if __name__ == '__main__':
app.run_server(host='1.2.3.4', port=8000)
/root/DashApp/wsgi.py
from index import app as application
if __name__ == '__main__':
application.run()
/root/DashApp/index.ini
[uwsgi]
module=wsgi
master=true
processes=2
socket=index.sock
chmod-socket=666
vacuum=true
die-on-term=true
/etc/systemd/system/index.service
[Unit]
Description=uWSGI instance to serve index
After=network.target
[Service]
User=root
Group=nginx #without User and Group doesn't work too
WorkingDirectory=/root/DashApp
ExecStart=/usr/local/bin/uwsgi --force-cwd /root/DashApp --ini index.ini
[Install]
WantedBy=multi-user.target
/etc/nginx/nginx.conf(此文件中没有服务器{})
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events{
worker_connections 768;
}
http {
auth_basic 'Log in, please'; #doesn't work too
auth_basic_user_file /etc/nginx/.htpasswd;
#Basic Settings - I didn't change this part
....
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/default
server {
listen 80;
server_name 1.2.3.4;
location / {
include uwsgi_params;
uwsgi_pass unix:/root/DashApp/index.sock;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /root/DashApp;
index index.py index.html index.htm index.gnix-debian.html;
auth_basic 'Log in, please';
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
autoindex on;
autoindex_exact_size off;
}
我愿意:
nginx -s reload
systemctl daemon-reload
systemctl start index.service
systemctl enable index
systemctl start nginx
systemctl enable nginx
nginx -t # writes 'ok'
我在 1.2.3.4 得到 403 Forbidden nginx/1.14.0 (Ubuntu) 和 'ConnectException: failed to connect' 尝试连接到 1.2.3.4:8000
“systemctl 状态索引”写道:
如何解决?
解决方案
我决定只使用 apache2 insetead of nginx + apache2(for auth)
这很容易
推荐阅读
- c - 检测素数的 C 程序
- swift - 尝试评估 NSExpression 或 NSPredicate 时的 SIGABRT
- r - 在 secr 包中删除重复检测的警告消息
- python - 如何在 Mac 上安装模块
- php - 在现有目录 PHP 中创建目录
- azure-devops - 如何自动创建 Azure DevOps Boards 备份以进行时间点还原?
- python-3.x - 使用 python 和 selenium 为每个选择选项标签获取控制台日志响应
- python - 如何使用 for 循环将整个 csv 文件写入字典
- typescript - 根据 TypeScript 中区分联合的参数自动推断返回类型
- c - 是什么导致我的 C 程序中出现此错误(分段错误(核心转储))?