Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"no python application found" uWSGI + nginx + Ubuntu 13

I understand this is a common question but I've seen so many examples with frankenstein ini files that make no sense. Based on different systems with different file system layouts:

e.g. /etc/uwsgi/vassals -vs- /etc/uwsgi/apps-{enabled|available} -vs- solo launching uwsgi

So please for the love of my sanity after 14hrs of of brain damage:

I have a basic Flask project with this layout:

/srv/py/mylovelyapp/mylovelyapp.py
                   /models.py
                   /database.py
                   /static/
                   /templates/

My monster of an ini file (located at /etc/uwsgi/apps-enabled/mylovelyapp.ini) is:

[uwsgi]
plugins = python
base = /srv/py/mylovelyapp
app = mylovelyapp
callable = app
gid = www-data
uid = www-data
vhost = true
socket = 127.0.0.1:3031
master = true
processes = 1
harakiri = 20
limit-as = 128

nginx config at /etc/nginx/sites-enabled/mysite.conf:

server {
listen 80;
server_name www.mylovelyapp.co.uk mylovelyapp.co.uk;

charset     utf-8;
client_max_body_size 75M;

location / { try_files $uri @yourapplication; }
location @yourapplication {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:3031;
}
location /static/ {
    alias /srv/py/mylovelyapp/static/;
    expires 30d;
    access_log off;
}

access_log /var/log/nginx/mylovelyapp-a.conf;
error_log /var/log/nginx/mylovelyapp-e.conf;
}

The error output I get when tailing the /var/log/uwsgi/mylovelyapp.log is this:

Mon May 26 06:41:40 2014 - *** Python threads support is disabled. You can enable it with --enable-threads ***
Mon May 26 06:41:40 2014 - Python main interpreter initialized at 0x1445e50
Mon May 26 06:41:40 2014 - your server socket listen backlog is limited to 100 connections
Mon May 26 06:41:40 2014 - your mercy for graceful operations on workers is 60 seconds
Mon May 26 06:41:40 2014 - mapped 145536 bytes (142 KB) for 1 cores
Mon May 26 06:41:40 2014 - *** Operational MODE: single process ***
Mon May 26 06:41:40 2014 - *** no app loaded. going in full dynamic mode ***
Mon May 26 06:41:40 2014 - *** uWSGI is running in multiple interpreter mode ***
Mon May 26 06:41:40 2014 - spawned uWSGI master process (pid: 2380)
Mon May 26 06:41:40 2014 - spawned uWSGI worker 1 (pid: 2388, cores: 1)

While visiting the URL gives the message:

Internal Server Error

I know I'm missing some easy reference but I'm trying allsorts of trual and error as well as Googling but comeing across examples that are all alightly unfitting for my use. An yet infuriatingly its such a simple app and setup!!

Please, please help. :(

P.S.. Bonus love and eternal gratitude if you can tell me how to make it use the virtual machine for that flask app.

P.P.S I've heard Gunicorn is easier - maybe I should switch to that?

like image 607
RustyFluff Avatar asked May 26 '14 06:05

RustyFluff


1 Answers

You should try to invest a bit of time in understanding all the components involved. For example you have merged the .ini uWSGI file with nginx.conf that is completely wrong. I can suggest you to start from here: http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html

Try to understand every step (expecially the part about using official sources instead of distro packages). Start deploying without nginx (only uWSGI), and only after you are sure the thing is clear, you can proxy it behind nginx.

About gunicorn, yes it easier in the sense that it is written in python (so you do not need a c compiler to build it) and it has a minimal set of features, that reduce the amount of different configs you could find on the net (but really, avoid blind cut & paste, you should invest in understanding what is going on, otherwise your site will be down for ages at the first little problem). From what i can see/understand/immagine from your message, at the current state, using a WSGI server or another will not make difference for you.

like image 93
roberto Avatar answered Oct 06 '22 02:10

roberto