2024-10-25 22:57:10 -04:00
|
|
|
worker_processes 1;
|
2025-01-10 19:41:03 -05:00
|
|
|
|
2024-10-25 22:57:10 -04:00
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
sendfile on;
|
|
|
|
keepalive_timeout 65;
|
|
|
|
|
2024-12-01 09:52:34 -05:00
|
|
|
client_max_body_size 100M;
|
|
|
|
|
2025-01-10 19:41:03 -05:00
|
|
|
# The backend is running in the same container, so reference localhost
|
2024-10-25 22:57:10 -04:00
|
|
|
upstream django {
|
2025-01-10 19:41:03 -05:00
|
|
|
server 127.0.0.1:8000; # Use localhost to point to Gunicorn running internally
|
2024-10-25 22:57:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
2025-01-18 17:03:03 -05:00
|
|
|
listen 80;
|
2024-10-25 22:57:10 -04:00
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
location / {
|
2025-01-10 19:41:03 -05:00
|
|
|
proxy_pass http://django; # Forward to the upstream block
|
2024-10-25 22:57:10 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
location /static/ {
|
|
|
|
alias /code/staticfiles/; # Serve static files directly
|
|
|
|
}
|
|
|
|
|
2025-01-18 17:03:03 -05:00
|
|
|
# Serve protected media files with X-Accel-Redirect
|
|
|
|
location /protectedMedia/ {
|
2025-05-22 16:26:50 -04:00
|
|
|
internal;
|
|
|
|
alias /code/media/;
|
|
|
|
try_files $uri =404;
|
|
|
|
|
|
|
|
# Nested location for PDFs
|
|
|
|
location ~* \.pdf$ {
|
|
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'none'; object-src 'none'; base-uri 'none'" always;
|
|
|
|
add_header X-Content-Type-Options nosniff always;
|
|
|
|
add_header X-Frame-Options SAMEORIGIN always;
|
|
|
|
add_header Content-Disposition "inline" always;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-18 17:03:03 -05:00
|
|
|
|
2024-10-25 22:57:10 -04:00
|
|
|
}
|
2025-01-18 17:03:03 -05:00
|
|
|
}
|