Learn how to deploy your newly created Django 2.0 project on any Ubuntu server. I will be going one by one from setting up Gunicorn, setting nginx, supervisor and all.
Part 2 of this series: • Django Deployment Part 2 - Integratio...
To get free $10 credit in Digital Ocean go through https://m.do.co/c/b64572e7a23c
I know deployment is little tricky especially when you are a beginner, that's why I thought to create a video on this. Just go step by step and comment if you face some error. The Internal server error and bad gateway errors occur frequently.
Look at part 2 of this video if you want to see how I resolved my error. A little mistake in the configuration file can hurt your progress a lot. So be careful while copy pasting these files from here.
#!/bin/bash
NAME="YOUR_PROJECT_NAME"
DIR=/home/YOUR_USERNAME/YOUR_PROJECT_NAME
USER=YOUR_USERNAME
GROUP=YOUR_USERNAME
WORKERS=3
BIND=unix:/home/YOUR_USERNAME/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=YOUR_PROJECT_NAME.settings
DJANGO_WSGI_MODULE=YOUR_PROJECT_NAME.wsgi
LOG_LEVEL=error
cd $DIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
-log-file=
If you see an error in logs/gunicorn-error.log regarding the location of gunicorn_start, you can add the absolute path. Start like this \\\home\USER_NAME\YOUR_PROJECT_NAME
[program:YOUR_PROJECT_NAME
command=/home/YOUR_USERNAME/bin/gunicorn_start
user=YOUR_USERNAME
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/YOUR_USERNAME/logs/gunicorn-error.log
_______________________________________________________________
Here is NGINX file:
_______________________________________________________________
server {
listen 80;
add here the ip address of your server
or a domain pointing to that ip (like example.com or www.example.com)
server_name YOUR_DOMAIN_OR_IP ;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /home/YOUR_USERNAME/logs/nginx-access.log;
error_log /home/YOUR_USERNAME/logs/nginx-error.log;
location /static/ {
alias /home/YOUR_USERNAME/static/;
}
checks for static ile, if not found proxy to app
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
Watch video Django 2.0 Deployment with Gunicorn, NGINX on Ubuntu (Works on Digital Ocean and AWS EC2) online without registration, duration hours minute second in high quality. This video was added by user Ultimate Backend & AI 20 September 2018, don't forget to share it with your friends and acquaintances, it has been viewed on our site 9,868 once and liked it 109 people.