Skip to content

Instantly share code, notes, and snippets.

@devbkhadka devbkhadka/
Last active Sep 16, 2019

What would you like to do?
provision ubuntu server to host django site using nginx and gunicorn
# this command is necessary to tell Systemd to load our new config file
elspeth@server:$ sudo systemctl daemon-reload
# this command tells Systemd to always load our service on boot
elspeth@server:$ sudo systemctl enable
# this command actually starts our service
elspeth@server:$ sudo systemctl start
# Check the Systemd logs for using
sudo journalctl -u
# You can ask Systemd to check the validity of your service configuration:
systemd-analyze verify /path/to/my.service.
# Remember to restart both services whenever you make changes.
# If you make changes to the Systemd config file, you need to run daemon-reload before systemctl restart to see the effect of your changes.
Description=Gunicorn server for
# needs full path of executable
ExecStart=/home/elspeth/sites/ \
--bind unix:/tmp/ \
add-apt-repository ppa:fkrull/deadsnakes
apt-get install nginx python3.6 python3.6-venv
Add Nginx config for virtual host at /etc/nginx/sites-available and create its symlink at /etc/nginx/sites-enabled
server {
listen 80;
location /static {
alias /home/ubuntu/uat/static;
location / {
proxy_set_header HOST $host;
proxy_pass http://unix:/tmp/;
Add Systemd job for Gunicorn
Create directory structure in ~/sites
Pull down source code into folder named source
Start virtualenv in ../virtualenv
pip install -r requirements.txt migrate for database
collectstatic for static files
Set DEBUG = False and ALLOWED_HOSTS in
Restart Gunicorn job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.