How to add HTTPS to Django with Nginx
Answered
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
Gold
•
255 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer