[英]Can't run dash app on server with nginx and uwsgi
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 狀態索引”寫道:
如何解決?
我決定只使用 nginx + apache2 的 apache2 insetead(用於身份驗證)
這很容易
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.