Installing required packages

The following command will install Python3, pip package installer, Nginx, and PostgreSQL on the Ubuntu machine,

# sudo apt install python3 python3-pip nginx postgresql postgresql-contrib

 

How to install Django with NGINX, Gunicorn, and PostgreSQL on Ubuntu?

This article describes how to install and configure Django with PostgreSQL, Gunicorn, and Nginx on your Ubuntu machine. First, let’s look at an overview of all the tools we use. Django is a robust, free, open-source, Python-based web framework that follows the MVT (Model-Template-View) architectural pattern. Though it includes an integrated development server for testing projects on your local system, however, using the development server for production is not recommended as it is not intended for this purpose. For this reason, we need a more robust and secure web server like Gunicorn that connects to Python applications via a WSGI interface. Nginx is a web server used as a reverse proxy with Gunicorn.

Similar Reads

Installing required packages

The following command will install Python3, pip package installer, Nginx, and PostgreSQL on the Ubuntu machine,...

Configure PostgreSQL:

Now let’s configure PostgreSQL  to work with Django, to interact with Postgres we need to use its interactive shell prompt which we can activate as follow,...

Setup a development environment

First, let us configure the virtual environment, this step can be skipped but it is always a good idea to use a dedicated development environment for each project, this can be achieved using a python virtual environment....

Creating and Configuring Django Project

Now that the development environment is configured we can start a Django project. Let’s create one by running the following commands....

Configure Gunicorn to serve the project

In the previous step, we used the built-in Django development server to run our project, but this is not a deployment server intended to be used only during development. Let’s run the Django project with Gunicorn using the following command:...

Creating system Socket and Service files for Gunicorn

Now that you’ve tested that Gunicorn with your Django application, you should implement a more robust way of starting and stopping the application server. To accomplish this, we will create systemd service and socket files, by running the following commands....

Enabling and checking socket and service files for Gunicorn

The following commands will start running the Gunicorn socket service and will enable it to start automatically on boot....

Configure Nginx proxy

At this point, the Gunicorn setup is complete. Next, we need to set up an Nginx server as a proxy to handle all HTTP traffic and forward it to Gunicorn for processing. First, create a new server block in the directory available to your Nginx site....