Skip to content

Commit

Permalink
added ssl config
Browse files Browse the repository at this point in the history
  • Loading branch information
fulanii committed Dec 18, 2024
1 parent ee1a070 commit 2cbf365
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
9 changes: 9 additions & 0 deletions autoblue_django/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@
},
}

SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

SECURE_HSTS_SECONDS = 31536000 # 1 year
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
25 changes: 21 additions & 4 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@ http {
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

upstream autoblue {
server web:8000;
server {
listen 80;
server_name autoblue.yassinecodes.dev;

# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}

server {
listen 80;
server_name autoblue.yassinecodes.dev www.autoblue.yassinecodes.dev;
server_name autoblue.yassinecodes.dev;

listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/autoblue.yassinecodes.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/autoblue.yassinecodes.dev/privkey.pem;

# SSL settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

# Proxy pass to Django (Gunicorn)
location / {
proxy_pass http://autoblue;
proxy_pass https://web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -40,6 +52,11 @@ http {
alias /staticfiles/;
}

# Redirect www to non-www
# if ($host = www.autoblue.yassinecodes.dev) {
# return 301 https://autoblue.yassinecodes.dev$request_uri;
# }

# Security headers
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "DENY";
Expand Down

0 comments on commit 2cbf365

Please sign in to comment.