Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CHANG-CHING-CHUNG/cc1c7093f02926240ae506e1a4532c65 to your computer and use it in GitHub Desktop.
Save CHANG-CHING-CHUNG/cc1c7093f02926240ae506e1a4532c65 to your computer and use it in GitHub Desktop.
Config for Django/Pipenv/Gunicorn/Nginx/Systemd.

Reasonable default configuration for a web app that uses Django and the following dependencies:

  • Pipenv: Python package manager
  • Gunicorn: WSGI server
  • Nginx: Static webserver passing to gunicorn, handling SSL, etc.
  • Systemd: Used to load Gunicorn on startup

This is my goto for setting up projects.

server {
listen 80;
server_name <domain>;
location /.well-known {
root /srv/ssl/<site>/;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
# Server declaration
listen 443 ssl;
client_max_body_size 200M;
server_name <domain>;
location /static {
root /srv/http/<site>;
}
location / {
include proxy_params;
proxy_pass http://unix:/srv/http/<site>/<site>.sock;
}
# SSL
ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/<domain>/chain.pem;
include /etc/nginx/snippets/intermediate.conf;
}
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=<site>
Group=<site>
WorkingDirectory=/srv/http/<site>
ExecStart=/usr/local/bin/pipenv run gunicorn --access-logfile - --workers 3 --bind unix:/srv/http/<site>/<site>.sock <site>.wsgi:application
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment