Setup nginx and uwsgi with python3 on ubuntu 14.04

First, install the needed components:

sudo apt-get install nginx uwsgi uwsgi-plugin-python3

Create nginx config for the new website:

sudo nano /etc/nginx/sites-available/

Add the following, change atleast server_name and root lines to match your setup:

server {
    error_log  /var/log/nginx/;
    access_log         /var/log/nginx/;
    root /home/youruser/web/;
    location / {
        uwsgi_pass unix:/var/run/uwsgi/app/myapp/socket;
        include uwsgi_params;

Save file and close your editor.

Make nginx use the new site:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Add uwsgi config for new site:

sudo nano /etc/uwsgi/apps-available/mysite.ini
# socket line should match uwsgi_pass line in your nginx config
socket = /var/run/uwsgi/app/myapp/socket
chown-socket = www-data
chdir = /home/youruser/web/
# Directory you can create to serve static files in the project, or just omit.
# This is the main python file in your project
file =

Make uwsgi use the new config:
sudo ln -s /etc/uwsgi/apps-available/mysite.ini /etc/uwsgi/apps-enabled/mysite.ini

Reload config:

sudo service uwsgi restart
sudo service nginx reload

If you do not already have a wsgi-compatible python web project to use with this setup, here is a small guide to get you started:

cd /home/youruser/web/

For this example I use


Add the following:

from bottle import route, run, template, default_app

def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

if __name__ == "__main__":
    run(host='localhost', port=8080)
    application = default_app()

You can now test your app at your_domain/hello/name

Comments are closed.