User Tools

Site Tools


Setting Up uWSGI for Zibawa

Configure NGINX for uWSGI

Uwsgi Params file

Check that you have the following file at:

sudo nano /etc/nginx/uwsgi_params

The file should look like this.

NGINX configuration file

sudo nano /etc/nginx/conf.d/zibawa.conf
#modify the server name to your IP or FQDN

upstream django {
    server unix:///tmp/zibawa.sock; # for a file socket
    #server; # alternative for a web port socket(we are not using this..)

# configuration of the server
server {

    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/html/media;  # your Django project's media files - amend as required

    location /static {
        alias /var/www/html/static; # your Django project's static files - amend as required

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file usually installed with nginx

Restart Nginx to apply changes

sudo systemctl restart nginx

Test uwsgi with Included in the zibawa distribution there is a file to test uwsgi. We will test with permissions 777 to avoid problems with permissions and to ensure our NGINX config is correct.

uwsgi --socket /tmp/zibawa.sock --wsgi-file /home/zibawa/zibawa/ --chmod-socket=777

If you navigate to <your domain name or IP> you should see “hello world”.

Run Zibawa using uWSGI

To run this command you must be in the Zibawa main directory (where is)

cd /home/zibawa/zibawa
uwsgi --socket /tmp/zibawa.sock --module zibawa.wsgi --chmod-socket=777

uwsgi ini file

There is a file called zibawa_uwsgi.ini inside the zibawa distribution. This file defines how the uwsgi should be run automatically, with secure permissions by the zibawa user and www-data group.

Before testing, you will need to remove the socket we created in the previous test (otherwize you will get error : bind(): Address already in use [core/socket.c line 230]

sudo rm /tmp/zibawa.sock

Test the uwsgi ini file using the following

sudo uwsgi --ini /home/zibawa/zibawa/zibawa_uwsgi.ini --uid zibawa --gid www-data

Use ctrl C to escape.

You must use sudo, or the process will run under your own user and cause errors because it is unable to write to the logs.

Create /etc/uwsgi/vassals directory and make sim link to above file

sudo mkdir /etc/uwsgi
sudo mkdir /etc/uwsgi/vassals
sudo ln -s /home/zibawa/zibawa/zibawa_uwsgi.ini /etc/uwsgi/vassals/

Now run uwsgi in emperor mode

sudo uwsgi --emperor /etc/uwsgi/vassals --uid zibawa --gid www-data

Setup uWSGI with systemd

Find out where uWSGI executable is

whereis uwsgi

Create emperor.uwsgi.service file as follows

sudo nano /etc/systemd/system/emperor.uwsgi.service
#in this file it may be necessary to change ExecStart according to where executable is

Description=uWSGI Emperor


ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini

# Requires systemd version 211 or newer


Also create emperor.ini file as specified in above file

sudo nano /etc/uwsgi/emperor.ini
emperor = /etc/uwsgi/vassals
uid = zibawa
gid = www-data

Now start and stop emperor service like any other systemd service

sudo systemctl restart emperor.uwsgi.service

To make reload on reboot

sudo systemctl daemon-reload
sudo systemctl enable emperor.uwsgi

For full information:

adm/setting_up_uwsgi.txt · Last modified: 2017/03/15 09:22 by matt