Book Image

Learning Raspberry Pi

By : Samarth Shah, Serge Schneider
Book Image

Learning Raspberry Pi

By: Samarth Shah, Serge Schneider

Overview of this book

Table of Contents (14 chapters)
Learning Raspberry Pi
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Deploying Flask applications


As mentioned earlier, running Flask applications by directly launching the script works for testing, but is extremely unsafe and slow. In order to use nginx as the server for Pi MusicBox, the following needs to be added to the server block of the nginx site's configuration file (/etc/nginx/sites-available/pisite):

location = /piMusic { rewrite ^ /piMusic/; }
location /piMusic { try_files $uri @piMusic; }
location @piMusic {
include uwsgi_params;
    uwsgi_param SCRIPT_NAME /piMusic;
    uwsgi_modifier1 30;
    uwsgi_passunix:/tmp/uwsgi.sock;
}

For consistency, the Pi MusicBox directory should be moved to /srv.

Next, uWSGI needs to be installed and configured. You can think of it as the glue that will connect your application to nginx. You can install it by running this:

# apt-get install uwsgi uwsgi-plugin-python

Then, create the app configuration file /etc/uwsgi/apps-available/piMusic.ini as follows:

[uwsgi]
plugins = python
socket =  /tmp/uwsgi.sock
module = piMusic...