uWSGI +nginx setup - Dash (Plotly) Deployment

Viewed 3293

I’m new to flask and the deployment procedure I have my dash.py setup as so

server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)

and my nginx file as such

server {
listen      80;
server_name localhost;
charset     utf-8;
client_max_body_size 75M;

location / {try_files $uri @yourapplication; }
location @yourapplication {
    include uwsgi_params;
    uwsgi_pass unix:/var/www/School-Dashboard/dash_clean.sock;
}
}

…but i’m not sure what i have to set the module parameter to in my wsgi ini file.

[uwsgi]
#application's base folder
base = /var/www/School-Dahboard

#python module to import
module = dash_clean:app #?????? WHAT DO I DO HERE

#home = %(base)/venv
pythonpath = %(base)

#socket file's location
socket = /var/www/School-Dashboard/dash_clean.sock

#permissions for the socket file
chmod-socket    = 660


#location of log files
logto = /var/log/uwsgi/%n.log

I keep getting a bad gateway error because of my uwsgi file.

This is the log from uwsgi.

Starting uWSGI 2.0.17.1 (64bit) on [Mon Nov  5 12:47:42 2018] ***
compiled with version: 5.4.0 20160609 on 03 November 2018 06:53:29
os: Linux-4.15.0-36-generic #39~16.04.1-Ubuntu SMP Tue Sep 25 08:59:23 UTC 2018
nodename: xxxxxxxx
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /var/www/School-Dashboard
detected binary path: /home/concent/.local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31145
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/School-Dashboard/dash_clean.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01)  [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x22b9330
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/School-Dahboard to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x22b9330 pid: 20070 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 20070, cores: 1)
2 Answers

So i've set up nginx as so...

server {
        server_name 0.0.0.0;
        listen 80;
        root /home/ubuntu/school_dashboard;
        client_max_body_size 200M;
        include /etc/nginx/default.d/*.conf;

location /dependencies {
   proxy_read_timeout 300;
    proxy_connect_timeout 300;
   proxy_pass http://0.0.0.0:5005;
        #index wsgi.py
        include uwsgi_params;
       uwsgi_pass unix:/home/ubuntu/school_dashboard/dependencies/urlgen.sock;
    }
}

and my uwsgi file as....

[uwsgi]
module = dash_clean:server

master = true
processes = 5

socket = dashboard.sock
chmod-socket = 660
vacuum = true

die-on-term = true

I just had to change the module parameter

The module parameter should be

module = dash:server

This is because the module is actually the name of your python file that instantiates the flask application instance. In this case it's in your dash.py. Although, in your subsequent comments you seem to reference dash_clean.py, in that case it should be:

module = dash_clean:server

The part after the module name is the name of the "callable", or the name of the variable that is the flask application.

You define it in your code example as:

server = flask.Flask(__name__)

Alternatively, you could define them seperately in the ini

module = dash
callable = server
Related