mercredi 23 septembre 2020

Can't run dash app on server with nginx and uwsgi

I try to run dash app on server using nginx and uwsgi following by this tutorial: https://levelup.gitconnected.com/the-easiest-way-to-host-a-multi-page-dashboard-using-python-dash-and-linux-for-beginners-78a78e821ba

The structure of folders:

/
---- etc/nginx...
---- root
     ---- DashApp
          ---- index.py
          ---- wsgi.py
          ---- index.ini

My dash app looks like this:

/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 (there is no server {} in this file)

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;
    }

I do:

nginx -s reload
systemctl daemon-reload
systemctl start index.service
systemctl enable index
systemctl start nginx
systemctl enable nginx
nginx -t # writes 'ok'

and I got 403 Forbidden nginx/1.14.0 (Ubuntu) at 1.2.3.4 and 'ConnectException: failed to connect' while trying to connect to 1.2.3.4:8000

'systemctl status index' writes: enter image description here

How to solve it?




Aucun commentaire:

Enregistrer un commentaire