45
I need to enable HTTPS for my Django site. How do I configure SSL?
Loading...
Q&A · Answered
I need to enable HTTPS for my Django site. How do I configure SSL?
Accepted answer
# Get SSL certificate
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
# nginx configuration
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / {
proxy_pass http://unix:/run/gunicorn.sock;
}
}
# settings.py
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = TrueSay what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.