server { listen 80; server_name yourdomain.com www.yourdomain.com; # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "no-referrer-when-downgrade" always; add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # Static files location /static/ { alias /home/ubuntu/django-demo/staticfiles/; expires 1y; add_header Cache-Control "public, immutable"; } # Media files (if you add file uploads later) location /media/ { alias /home/ubuntu/django-demo/media/; expires 1y; add_header Cache-Control "public"; } # Django application location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; # Timeouts proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; } # Block access to sensitive files location ~* /\.(?!well-known\/) { deny all; } location ~* /(requirements\.txt|\.env|deploy/) { deny all; } }