Tag Archives: uwsgi

Running Python CGI Scripts on the Raspberry Pi

Python is the language of choice for controlling the Raspberry Pi’s GPIO pins. It seems only natural then that to interact with your Pi over the web it should run a web server able to handle Python CGI scripts. Following the steps below will get the lightweight nginx web server running on your Pi, handing Python requests off to a uwsgi helper process.

  1. Install nginx
  2. Add a location to the /etc/nginx/sites-available/default to pass Python requests on to uwsgi. This needs to be placed inside the “server” block of the configuration, for example right after one of the existing “location” sections.
  3. Create a Python CGI script at /usr/share/nginx/www/hello.py
  4. Start nginx
  5. Build and install the uwsgi with the cgi plugin
  6. Create the file /etc/uwsgi.ini
  7. Create the file /usr/share/nginx/www/hello.py
  8. Create an init script for uwsgi at /etc/init.d/uwsgi
  9. Start uwsgi and configure it to start on boot
  10. Open up your web browser and go to http://{your pi’s ip address}/hello.py
    If you’re using the browser on your Pi then you could instead go to http://localhost/hello.py
    If you see the message “Hello World” then everything is working.
    Hello_World