Laurence Mercer

How to configure Gunicorn to serve multiple Django and Wagtail projects

When first deploying a Django or Wagtail project to DigitalOcean, and assuming you're using the relevant stack, it can be helpful to follow the community tutorial 'How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu'.

As part of this tutorial, step 7 covers 'Creating systemd Socket and Service Files for Gunicorn'. Therein, the advice is to create the following socket and service files:

/etc/systemd/system/gunicorn.socket
/etc/systemd/system/gunicorn.service

This works as expected. However, what's less clear from the tutorial is that these files are specific to an individual project, rather than Gunicorn as a whole. Therefore, in order to subsequently deploy a second Django or Wagtail project to the same hosting instance, it is necessary to create two new Gunicorn files, which must have a different name. For example:

/etc/systemd/system/gunicorn-site2.socket
/etc/systemd/system/gunicorn-site2.service

The second project's socket and service files can then, for example, be referenced like so:

sudo systemctl status gunicorn-site2.socket
sudo systemctl status gunicorn-site2

Return to blog