Nginx – Bottle.py app can’t be found by nginx+uwsgi

nginxpythonuwsgi

I have a Python 3 bottle.py app that I install into a virtual environment (letting pip automatically fetch dependencies). I'm trying to get it to run under nginx and uwsgi on my raspberry pi.

When I have nginx and uwsgi running, visiting http://localhost/icecrate results in "uWSGI Error Python application not found". I assume this means nginx is properly connecting to uwsgi, and it is uwsgi that can't find the application.

However, If I run the app with uwsgi --http 0.0.0.0:8080 /etc/uwsgi/apps-enabled/icecrate.ini then http://localhost:8080 gives me the application, which suggests the uwsgi config is at least adequate.

I've been searching Google and the docs for a few hours for a solution. I don't know what I'm doing wrong here.

/etc/nginx/sites-available/icecrate

server {
  listen      80;
  server_name raspberrypi;

  access_log  /home/icecrate/logs/access.log;
  error_log   /home/icecrate/logs/error.log;

  location /icecrate {
    uwsgi_pass unix:///tmp/icecrate.sock;
    include    uwsgi_params;
  }
}

/etc/uwsgi/apps-available/icecrate.ini

[uwsgi]
vhost = true
plugins = python3
socket = /tmp/icecrate.sock
master = true
enable-threads = false
processes = 1

# this just imports the app callable and renames it to application
wsgi-file = /home/icecrate/nginx.py

# I get the same results using this method
#module = icecrate.web
#callable = app

virtualenv = /home/icecrate/env
touch-reload = /home/icecrate/reload

Application code is at GitHub.

Best Answer

I ended up nuking the attempt and all the configs and starting over, but I think I got this figured out. I'm fairly certain it was a permissions issue.

By default nginx.conf specified www-data as the user it runs as, and the previous attempt made no effort at dealing with that. All files were owned by myself. Rather than change the default user, I made a home folder for www-data, which now holds the icecrate virtualenv. When setting up the app, I used sudo -s -u www-data to do all the file creation, so all the files have the proper owner and permissions.

The Nginx config is essentially the same, except the virtualenv folder now plays home to the socket and logs:

server {
  listen 80;
  server_name = raspberrypi;

  access_log /home/www-data/icecrate/logs/access.log;
  error_log /home/www-data/icecrate/logs/error.log;

  location /icecrate {
    uwsgi_pass unix:///home/www-data/icecrate/icecrate.sock;
    include uwsgi_params;
  }
}

I skipped some things that looked not important to the problem while rebuilding the uwsgi app ini, but it too is essentially the same:

[uwsgi]
plugins = python3
socket  = /home/www-data/icecrate/icecrate.sock
module  = icecrate.web:app
virtualenv = /home/www-data/icecrate
touch-reload = /home/www-data/icecrate/reload

# like ngnix, uwsgi should be www-data.
uid = www-data
gid = www-data

# don't think this works, though
logto = /home/www-data/icecrate/logs/uwsgi.log

After putting the config files in sites-enabled and apps-enabled respectively, I started nginx and uwsgi and pointed my browser at http://localhost/icecrate and got a bottle.py 404 error. I don't think I've ever been so happy in my life to see a 404.