Reference and guides to build kick ass raspberry pi projects.
View the Project on GitHub codingforentrepreneurs/Pi-Awesome
ssh pi@raspberry
sudo apt install update
sudo apt install python3-venv -y
cd ~/
mkdir app
cd app
python3 -m venv .
source bin/activate
which python
pip install flask
server.py
Note that
server.py
is a name I made up for this app. You can call itwelcome.py
or whatever you like;server.py
makes sense for this app and for future devs to use it.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8123)
Note the values for
host
andport
in this example.host="0.0.0.0"
andport=8123
. We need these for later.
/home/pi/app/bin/python /home/pi/app/server.py
pi
is my user/home/pi
is my users’ root. (A shortcut to this path is cd ~/
)/home/pi/app/bin/python
is what which python
gave us from above/home/pi/app/server.py
is the absolute to my server.py
file I made above./home/pi/app/nginx.conf
upstream flaskapp {
server localhost:8123;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
location / {
proxy_pass http://flaskapp;
proxy_redirect off;
}
}
upstream
flaskapp
name is used 2 times and is arbitaryserver localhost:8123;
references the host
and port
values from the Flask app above."0.0.0.0"
is localhost
proxy_pass
references the upstream
name and not the localhost.sudo cp /home/pi/app/nginx.conf /etc/nginx/sites-enabled/default
/etc/nginx/sites-enabled/default
is linked to /etc/nginx/sites-available/default
(so you can recover if you need)sudo systemctl reload nginx
/home/pi/app/bin/python /home/pi/app/server.py
This value is discussed above.
If you open your browser at http://raspberrypi
you should see the Flask application data.