Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Raspberry Pi

You're reading from   Learning Raspberry Pi Unlock your creative programming potential by creating web technologies, image processing, electronics- and robotics-based projects using the Raspberry Pi

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781783982820
Length 258 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Serge Schneider Serge Schneider
Author Profile Icon Serge Schneider
Serge Schneider
Samarth Shah Samarth Shah
Author Profile Icon Samarth Shah
Samarth Shah
Arrow right icon
View More author details
Toc

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...
You have been reading a chapter from
Learning Raspberry Pi
Published in: Apr 2015
Publisher:
ISBN-13: 9781783982820
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image