🚀Django Deployment
Django Deployment to Ubuntu 18.04
Security & Access
Creating SSH keys (Optional)
$ ssh-keygen~/.ssh/id_rsa
~/.ssh/id_rsa.pub$ cat ~/.ssh/id_rsa.pubLogin To Your Server
Create a new user
Give root privileges
SSH keys for the new user
Exit the server
Log back into the server
Add SSH key for new user
Login as new user
Disable root login
Change the following
Reload sshd service
Simple Firewall Setup
Allow OpenSSH
Enable firewall
To check status
Software
Update packages
Install Python 3, Postgres & NGINX
Postgres Database & User Setup
Create a database
Create user
Set default encoding, transaction isolation scheme (Recommended from Django)
Give the User access to the database
Quit out of Postgres
Virtual Environment
Create a project directory
Create venv
Activate the environment
Git & Upload
Pip dependencies
Clone the project into the app folder on your server (Either HTTPS or setup SSH keys)
Install pip modules from requirements
Local Settings Setup
Run Migrations
Create superuser
Create static files
Create an exception for port 8000
Run Server
Test the site at YOUR_SERVER_IP:8000
Gunicorn Setup
Install gunicorn
Add to requirements.txt
Test Gunicorn serve
Stop server & deactivate virtual env
Open gunicorn.socket file
Copy this code, paste it in and save
Open gunicorn.service file
Copy this code, paste it in and save
Start and enable Gunicorn socket
Check the status of guinicorn
Check the existence of gunicorn.sock
NGINX Setup
Create a project folder
Copy this code and paste into the file
Enable the file by linking to the sites-enabled dir
Test NGINX config
Restart NGINX
Remove port 8000 from firewall and open up our firewall to allow normal traffic on port 80
You will probably need to up the max upload size to be able to create listings with images
Add this to the http{} area
Reload NGINX
Media File Issue
Domain Setup
Go to local_settings.py on the server and change "ALLOWED_HOSTS" to include the domain
Edit /etc/nginx/sites-available/btre_project
Reload NGINX & Gunicorn
Last updated