{"id":40130,"date":"2022-02-07T12:30:00","date_gmt":"2022-02-07T18:30:00","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=40130"},"modified":"2022-06-03T03:31:25","modified_gmt":"2022-06-03T08:31:25","slug":"how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/","title":{"rendered":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"742\" height=\"372\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg\" alt=\"how to set up django with postgres nginx and gunicorn on ubuntu 20.04\" class=\"wp-image-40255\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg 742w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04-300x150.jpg 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04-150x75.jpg 150w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/figure>\n\n\n\n<p>Django is an open-source web framework written in Python. It is a popular all-in-one web framework and one of the top choices for many developers. Django offers many advantages, such as MVT (Model View Template) architecture, automatic admin panel, and powerful ORM (Object Relational Mapping) database support. It also offers awesome debugging tools for developers. In this tutorial, we will show you how to install <a href=\"https:\/\/www.djangoproject.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Django <\/a>with PostgreSQL as the database storage instead of the default SQLite, Nginx as the reverse proxy, and Gunicorn as the application server <a href=\"https:\/\/www.rosehosting.com\/ubuntu-hosting.html\">on Ubuntu 20.04<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69eebadc9161e\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69eebadc9161e\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-1-Log-in-to-the-server\" >Step 1. Log in to the server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-2-Create-a-system-user\" >Step 2. Create a system user<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-3-Install-Packages\" >Step 3. Install Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-4-Add-Database-and-Database-User\" >Step 4. Add Database and Database User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-5-Create-Python-Virtual-Environment\" >Step 5. Create Python Virtual Environment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-6-Create-Django-Project\" >Step 6. Create Django Project<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-7-Create-Gunicorn-Systemd-File\" >Step 7. Create Gunicorn Systemd File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-8-Configure-Nginx\" >Step 8. Configure Nginx<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#Step-9-Install-SSL-Certificate\" >Step 9. Install SSL Certificate<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An Ubuntu 20.04 VPS<\/li><li>SSH access with root privileges<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-1-Log-in-to-the-server\"><\/span>Step 1. Log in to the server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>First, log in to your Ubuntu 20.04 server through SSH as the root user:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh root@IP_Address -p Port_number<\/pre>\n\n\n\n<p>You will need to replace \u2018IP_Address\u2018 and \u2018Port_number\u2018 with your server\u2019s respective IP address and SSH port number. Additionally, replace \u2018root\u2019 with the username of the admin account if necessary.<\/p>\n\n\n\n<p>Before starting, you have to make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># apt update -y\n# apt upgrade -y<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-step-2-create-a-system-user\"><span class=\"ez-toc-section\" id=\"Step-2-Create-a-system-user\"><\/span>Step 2. Create a system user<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Once logged in to Ubuntu 20.04 as root, we will create a new system user and grant it with sudo privileges. We will also use this user to complete this installation. In this tutorial, we will create a new system user called &#8216;master&#8217;, you can choose any username you like.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># adduser master<\/pre>\n\n\n\n<p id=\"h-once-created-let-s-run-this-command-to-add-the-new-user-to-sudo-group-in-ubuntu-users-who-are-members-of-sudo-group-are-allowed-to-run-sudo-commands\">Once created, let&#8217;s run this command to add the new user to sudo group. In Ubuntu, users who are members of sudo group are allowed to run sudo commands.<\/p>\n\n\n\n<pre id=\"h-usermod-ag-sudo-master\" class=\"wp-block-preformatted\"># usermod -aG sudo master<\/pre>\n\n\n\n<p>We will also add user master to our www-data group<\/p>\n\n\n\n<pre id=\"h-usermod-ag-www-data-master\" class=\"wp-block-preformatted\"># usermod -aG www-data master<\/pre>\n\n\n\n<p>Now, we can log in as the new user &#8216;master&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># su - master<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-3-Install-Packages\"><\/span>Step 3. Install Packages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To start this, we will install every required package from the repository. To install Nginx, PostgreSQL, Python from the repository, we can run this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt install postgresql postgresql-contrib python3-pip python3-dev libpq-dev nginx -y<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-4-Add-Database-and-Database-User\"><\/span>Step 4. Add Database and Database User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>During the PostgreSQL installation, a system user named postgres was created as the default administrative user. We need to use this user to log in to the PostgreSQL shell and perform administrative tasks.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -u postgres psql<\/pre>\n\n\n\n<p>You will be asked for your &#8216;master&#8217; password and the shell would be like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">postgres=#<\/pre>\n\n\n\n<p>While in the postgreSQL shell, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">postgres=# CREATE USER djangouser WITH PASSWORD 'm0d1fyth15';<br>postgres=# CREATE DATABASE djangodb;<\/pre>\n\n\n\n<p>Next, we also need to change the encoding to UTF-8, the timezone and default_transaction_isolation database scheme.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">postgres=# ALTER ROLE djangouser SET client_encoding TO 'utf8';<br>postgres=# ALTER ROLE djangouser SET default_transaction_isolation TO 'read committed';<br>postgres=# ALTER ROLE djangouser SET timezone TO 'UTC';<\/pre>\n\n\n\n<p>The last part, we grant the privileges to the new database then exit PostgreSQL shell.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">postgres=# GRANT ALL PRIVILEGES ON DATABASE djangodb TO djangouser;<br>postgres=# \\q<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-5-Create-Python-Virtual-Environment\"><\/span>Step 5. Create Python Virtual Environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Django can be installed in several ways, in this article we will show you how to install it in a python virtual environment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -H pip3 install --upgrade pip<br>$ sudo -H pip3 install virtualenv<\/pre>\n\n\n\n<p>Once completed, let&#8217;s create a new directory for django installation then enter to the new directory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mkdir django &amp;&amp; cd $_<\/pre>\n\n\n\n<p>After entering the &#8216;django&#8217; directory, we can run this command to create a new virtual environment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ virtualenv djangoenv<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv-1024x106.png?v=1640561197\" alt=\"\" class=\"wp-image-40131\" width=\"1024\" height=\"106\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv-1024x106.png 1024w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv-300x31.png 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv-150x16.png 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv-768x80.png 768w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-virtualenv.png 1184w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As seen in the picture, the new virtual environment is created in directory &#8216;djangoenv&#8217;. To install Django, Gunicorn and Psycopg2 in the virtual environment, we have to activate it first.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ source djangoenv\/bin\/activate<\/pre>\n\n\n\n<p>By running the command above, your shell will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$<\/pre>\n\n\n\n<p>While in the shell, run this command to install django.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ pip install django gunicorn psycopg2<\/pre>\n\n\n\n<p>Once completed, you should see an output like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Installing collected packages: sqlparse, backports.zoneinfo, asgiref, psycopg2, gunicorn, django<br>Successfully installed asgiref-3.4.1 backports.zoneinfo-0.2.1 django-4.0 gunicorn-20.1.0 psycopg2-2.9.2 sqlparse-0.4.2<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install-1024x340.png?v=1640561308\" alt=\"\" class=\"wp-image-40132\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install-1024x340.png 1024w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install-300x99.png 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install-150x50.png 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install-768x255.png 768w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-pip-install.png 1321w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>All required components to start a django project should be installed in the virtual environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-6-Create-Django-Project\"><\/span>Step 6. Create Django Project<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the previous step, we created a directory <code>~\/django<\/code> or in this case <code>\/home\/master\/django<\/code>. We will create a django project in this directory, we can run this command to install django project in <code>~\/django<\/code>. The command should be ran while we are in the virtual environment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ django-admin startproject djangoproject ~\/django<\/pre>\n\n\n\n<p>The command above will install django project in to <code>~\/django\/djangoproject<\/code>. If you list the directory, you will see <code>manage.py<\/code>, <code>djangoenv<\/code>, and <code>djangoproject<\/code> in your <code>~\/django<\/code>.<\/p>\n\n\n\n<p>Now, since we want to use PostgreSQL as the database storage, we need to modify the configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ nano ~\/django\/djangoproject\/settings.py<\/pre>\n\n\n\n<p>Add this line at the top of your settings.py<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<\/pre>\n\n\n\n<p>And replace the existing database information with the following.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql_psycopg2',\n        'NAME': 'djangodb',\n        'USER': 'djangouser',\n        'PASSWORD': 'm0d1fyth15',\n        'HOST': 'localhost',\n        'PORT': '',\n    }\n}<\/pre>\n\n\n\n<p>Make sure the database username and password match with the one we created in the previous step. Still in the same settings.py file, find ALLOWED_HOSTS then you can add your server IP adress, domain names, sub domain names. The entries should be seperated by a comma and listed in quotations.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALLOWED_HOSTS = ['123.123.123.123', 'domain.com', 'sub.domain.com']<\/pre>\n\n\n\n<p>Next, find the Django&#8217;s static files configuration. The changes is required to make your Django static files accessible through nginx, and to prevent nginx from returning error 404 messages. Add this line after STATIC_URL = &#8216;\/static\/&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">STATIC_ROOT = os.path.join(BASE_DIR, 'static\/')<\/pre>\n\n\n\n<p>Do not forget to save the changes then exit.<\/p>\n\n\n\n<p>Next, it is time to migrate the initial database schema to our PostgreSQL database, let&#8217;s run these commands.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ ~\/django\/manage.py makemigrations<br>(djangoenv) master@ubuntu20:~\/django$ ~\/django\/manage.py migrate<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"698\" height=\"379\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-migrate.png\" alt=\"\" class=\"wp-image-40133\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-migrate.png 698w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-migrate-300x163.png 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-migrate-150x81.png 150w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/figure>\n\n\n\n<p>Then, create a superuser.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ ~\/django\/manage.py createsuperuser<\/pre>\n\n\n\n<p>You will be asked to create a username, provide an email address and the username&#8217;s password. You would want to save the information about this administrative user and password because you will use them to log in to Django backend.<\/p>\n\n\n\n<p>For the last one, run the command below to collect static files.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ ~\/django\/manage.py collectstatic<\/pre>\n\n\n\n<p>You will need to confirm the action by answering it with yes then you will see this output after confirming:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">128 static files copied to '\/home\/master\/django\/static'<\/pre>\n\n\n\n<p>Deactivate the virtual environment to exit.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(djangoenv) master@ubuntu20:~\/django$ deactivate<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-7-Create-Gunicorn-Systemd-File\"><\/span>Step 7. Create Gunicorn Systemd File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To manage Gunicorn service, we will create a systemd unit file at  \/etc\/systemd\/system\/gunicorn.service.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo nano \/etc\/systemd\/system\/gunicorn.service<\/pre>\n\n\n\n<p>Paste these lines<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=gunicorn daemon\nAfter=network.target\n\n[Service]\nUser=master\nGroup=www-data\nWorkingDirectory=\/home\/master\/django\nExecStart=\/home\/master\/django\/djangoenv\/bin\/gunicorn --access-logfile - --workers 3 --bind unix:\/home\/master\/django\/djangoproject.sock djangoproject.wsgi:application\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p>Save the file then exit. Then reload systemd and start gunicorn.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo systemctl daemon-reload<br>$ sudo systemctl start gunicorn<\/pre>\n\n\n\n<p>To check whether gunicorn is running or not, run this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo systemctl status gunicorn<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"179\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-1024x179.png?v=1640561813\" alt=\"\" class=\"wp-image-40134\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-1024x179.png 1024w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-300x52.png 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-150x26.png 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-768x134.png 768w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-1536x269.png 1536w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn-1320x231.png 1320w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/systemctl-status-gunicorn.png 1756w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-8-Configure-Nginx\"><\/span>Step 8. Configure Nginx<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Gunicorn is running and we are now ready to configure nginx to act as a reverse proxy to our Django project. Let&#8217;s create an nginx server block for Django and delete the nginx default server block.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo rm \/etc\/nginx\/sites-enabled\/default\n$ sudo nano \/etc\/nginx\/conf.d\/django.conf<\/pre>\n\n\n\n<p>Paste these lines in <code> \/etc\/nginx\/conf.d\/django.conf <\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n    listen 80;\n    server_name 123.123.123.123;\n\n    location = \/favicon.ico { access_log off; log_not_found off; }\n    location \/static\/ {\n        alias \/home\/master\/django\/static\/;\n        }\n    location \/.well-known {\n    \talias \/home\/master\/django\/;\n\t\t}\n    \n\n    location \/ {\n        include proxy_params;\n        proxy_pass http:\/\/unix:\/home\/master\/django\/djangoproject.sock;\n    }\n}<\/pre>\n\n\n\n<p>Before saving the files, make sure you replace <code><strong>123.123.123.123<\/strong><\/code> with your server&#8217;s actual IP address and the socket path is correct. Then, check for any error and restart nginx to reload the new configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo nginx -t\n$ sudo systemctl restart nginx<\/pre>\n\n\n\n<p>At this point, you should be able to access your Django project at <code><strong>http:\/\/YOUR_SERVER_IP_ADDRESS<\/strong><\/code> and the administrative URL at <code><strong>http:\/\/YOUR_SERVER_IP_ADDRESS\/admin<\/strong><\/code> using your favorite web browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-9-Install-SSL-Certificate\"><\/span>Step 9. Install SSL Certificate<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This step is optional but highly recommended to complete. In the modern era, websites should run in HTTPS instead of HTTP. This step will walk you through SSL installation from Let&#8217;s Encrypt.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt install certbot python3-certbot-nginx -y<\/pre>\n\n\n\n<p>Once installed, edit your Django website server block and replace the server_name with your actual domain or subdomain pointed to your server IP address. Make sure the domain or subdomain DNS record is already pointed to your server prior to issuing the SSL certificate.<\/p>\n\n\n\n<p>Open<code> \/etc\/nginx\/conf.d\/django.conf<\/code> and edit this part<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n    listen 80;\n    server_name 123.123.123.123;<\/pre>\n\n\n\n<p>to<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n    listen 80;\n    server_name yourdomain.com;<\/pre>\n\n\n\n<p>Make sure to replace <code>yourdomain.com<\/code> with your actual domain name. Save the file then exit and reload Nginx.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo systemctl reload nginx<\/pre>\n\n\n\n<p>Now, we are ready to install the SSL certificate, run this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo certbot<\/pre>\n\n\n\n<p>You would need to provide your email address, accept the Let&#8217;s Encrypt TOS, and whether you want to share your email address with the Electronic Frontier Foundation or not. Then, you need to choose which names would you like to activate HTTPS for. Choose your Django website by typing the number and hitting ENTER. Let&#8217;s encrypt will install the certificate and it will ask you whether to configure HTTP to HTTPS redirect or not, you can choose redirect then certbot will create the redirection and reload Nginx if everything is okay.<\/p>\n\n\n\n<p>Now, you should be able to access your Django website in HTTPS mode at <code>https:\/\/yourdomain.com<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"718\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed-1024x718.png?v=1640647957\" alt=\"\" class=\"wp-image-40153\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed-1024x718.png 1024w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed-300x210.png 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed-150x105.png 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed-768x538.png 768w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2021\/12\/django-gunicorn-nginx-installed.png 1303w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>That&#8217;s it, you have learned how to set up Django with PostgreSQL, Nginx, and Gunicorn.<\/p>\n\n\n\n<p>Of course, you don\u2019t have to set up Django with PostgreSQL, Nginx, and Gunicorn on Ubuntu 20.04 if you use one of our <a href=\"https:\/\/www.rosehosting.com\/django-hosting.html\" target=\"_blank\" rel=\"noreferrer noopener\">Django VPS Hosting<\/a> services, in which case you can simply ask our expert Linux admins to set up Django with PostgreSQL, Nginx, and Gunicorn on Ubuntu 20.04 VPS for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n\n\n\n<p>PS. If you liked this post on how to set up Django with PostgreSQL, Nginx, and Gunicorn on Ubuntu 20.04, please share it with your friends on the social networks using the buttons below or simply leave a reply in the comments sections. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Django is an open-source web framework written in Python. It is a popular all-in-one web framework and one of the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04\" class=\"read-more button\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#more-40130\" aria-label=\"Read more about How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":40255,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,1698,1712],"tags":[862,1789,49,1984,1839],"class_list":["post-40130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-ubuntu","category-web-frameworks","tag-django","tag-gunicorn","tag-nginx","tag-postgres","tag-ubuntu-20-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting<\/title>\n<meta name=\"description\" content=\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04\" \/>\n<meta property=\"og:description\" content=\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:site_name\" content=\"RoseHosting\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoseHosting\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rosehosting.helpdesk\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-07T18:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-03T08:31:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg?v=1643186858\" \/>\n\t<meta property=\"og:image:width\" content=\"742\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jeff Wilson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:site\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Wilson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/\"},\"author\":{\"name\":\"Jeff Wilson\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\"},\"headline\":\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04\",\"datePublished\":\"2022-02-07T18:30:00+00:00\",\"dateModified\":\"2022-06-03T08:31:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/\"},\"wordCount\":1351,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg\",\"keywords\":[\"django\",\"gunicorn\",\"nginx\",\"postgres\",\"Ubuntu 20.04\"],\"articleSection\":[\"Tutorials\",\"Ubuntu\",\"Web Frameworks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/\",\"name\":\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg\",\"datePublished\":\"2022-02-07T18:30:00+00:00\",\"dateModified\":\"2022-06-03T08:31:25+00:00\",\"description\":\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg\",\"width\":742,\"height\":372,\"caption\":\"how to set up django with postgres nginx and gunicorn on ubuntu 20.04\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"name\":\"RoseHosting.com\",\"description\":\"Premium Linux Tutorials Since 2001\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\",\"name\":\"RoseHosting\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"width\":192,\"height\":192,\"caption\":\"RoseHosting\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoseHosting\",\"https:\\\/\\\/x.com\\\/rosehosting\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/rosehosting\\\/\"],\"description\":\"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.\",\"email\":\"info@rosehosting.com\",\"telephone\":\"(314) 275-0414\",\"legalName\":\"Rose Web Services LLC\",\"foundingDate\":\"2001-04-02\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\",\"name\":\"Jeff Wilson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"caption\":\"Jeff Wilson\"},\"description\":\"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.\",\"sameAs\":[\"https:\\\/\\\/www.rosehosting.com\",\"https:\\\/\\\/www.facebook.com\\\/rosehosting.helpdesk\"],\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/author\\\/jwilson\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting","description":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04","og_description":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting","og_url":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/","og_site_name":"RoseHosting","article_publisher":"https:\/\/www.facebook.com\/RoseHosting","article_author":"https:\/\/www.facebook.com\/rosehosting.helpdesk","article_published_time":"2022-02-07T18:30:00+00:00","article_modified_time":"2022-06-03T08:31:25+00:00","og_image":[{"width":742,"height":372,"url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg?v=1643186858","type":"image\/jpeg"}],"author":"Jeff Wilson","twitter_card":"summary_large_image","twitter_creator":"@rosehosting","twitter_site":"@rosehosting","twitter_misc":{"Written by":"Jeff Wilson","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#article","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/"},"author":{"name":"Jeff Wilson","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713"},"headline":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04","datePublished":"2022-02-07T18:30:00+00:00","dateModified":"2022-06-03T08:31:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/"},"wordCount":1351,"commentCount":0,"publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg","keywords":["django","gunicorn","nginx","postgres","Ubuntu 20.04"],"articleSection":["Tutorials","Ubuntu","Web Frameworks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/","url":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/","name":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#primaryimage"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg","datePublished":"2022-02-07T18:30:00+00:00","dateModified":"2022-06-03T08:31:25+00:00","description":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04 | RoseHosting","breadcrumb":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#primaryimage","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/01\/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20.04.jpg","width":742,"height":372,"caption":"how to set up django with postgres nginx and gunicorn on ubuntu 20.04"},{"@type":"BreadcrumbList","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-setup-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rosehosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Setup Django with Postgres, Nginx and Gunicorn on Ubuntu 20.04"}]},{"@type":"WebSite","@id":"https:\/\/www.rosehosting.com\/blog\/#website","url":"https:\/\/www.rosehosting.com\/blog\/","name":"RoseHosting.com","description":"Premium Linux Tutorials Since 2001","publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rosehosting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.rosehosting.com\/blog\/#organization","name":"RoseHosting","url":"https:\/\/www.rosehosting.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","width":192,"height":192,"caption":"RoseHosting"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoseHosting","https:\/\/x.com\/rosehosting","https:\/\/www.linkedin.com\/in\/rosehosting\/"],"description":"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.","email":"info@rosehosting.com","telephone":"(314) 275-0414","legalName":"Rose Web Services LLC","foundingDate":"2001-04-02","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713","name":"Jeff Wilson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","caption":"Jeff Wilson"},"description":"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.","sameAs":["https:\/\/www.rosehosting.com","https:\/\/www.facebook.com\/rosehosting.helpdesk"],"url":"https:\/\/www.rosehosting.com\/blog\/author\/jwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/40130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/comments?post=40130"}],"version-history":[{"count":12,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/40130\/revisions"}],"predecessor-version":[{"id":40289,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/40130\/revisions\/40289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media\/40255"}],"wp:attachment":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media?parent=40130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/categories?post=40130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/tags?post=40130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}