How to add HTTPS to Django with Nginx

Answered
Jan 05, 2026 1854 views 1 answers
45

I need to enable HTTPS for my Django site. How do I configure SSL?

D
Asked by devops_guru
Gold 290 rep

1 Answer

19
# 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 = True
N
Answered by noor_code 1 week, 2 days ago
Gold 255 rep

Your Answer

You need to be logged in to answer questions.

Log In to Answer