nginx + gunicorn + Django = Production-ready

> How to deploy a django project using gunicorn and nginx. Also to add ssl certificate from certbot

How to create your own django project?

mkdir dummyproj && cd dummyproj
python3 -m venv newenv
source newenv/bin/activate
pip3 install Django startproject hello

cd hello/

python runserver

Making it production ready…

pip3 install gunicorn
gunicorn hello.wsgi:application --bind
sudo vim /etc/systemd/system/gunicorn-hello.service
Description=gunicorn daemon

User=ayedaemon ## User who has permissions to the WorkingDirectory
## Directory where the project resides

## What command will start by this service
ExecStart=/home/ayedaemon/dummyproj/newenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/home/ayedaemon/dummyproj/hello.sock\

curl --unix-socket /home/ayedaemon/dummyproj/hello.sock localhost
sudo vim /etc/nginx/sites-available/helloproj.conf
listen 1234;
server_name <your domain name>; ## Add your domain name or ip on which it'll be hosted

location /static/ {
alias /home/ayedaemon/dummyproj/hello/static/;

location / {
include proxy_params;
proxy_pass http://unix:/home/ayedaemon/dummyproj/hello.sock;
sudo ln -s /etc/nginx/sites-available/helloproj.conf /etc/nginx/sites-enabled
sudo systemctl daemon-reload
sudo systemctl restart gunicorn-hello.service
sudo systemctl restart nginx

How to install certbot ssl certificate?

Connecting the dots and rest is magic.