Files
pagasis/docker/nginx.conf
T
Valeria López 9d0d0b6f56 Agrgar SSL
2025-10-21 04:14:58 -06:00

110 lines
3.5 KiB
Nginx Configuration File

upstream backend {
server backend:8000;
}
# Servidor HTTPS (SSL/TLS)
# NOTA: Solo se expone puerto 443. No hay redirección HTTP->HTTPS
# Los usuarios DEBEN acceder directamente vía HTTPS
server {
listen 443 ssl http2;
server_name localhost;
client_max_body_size 100M;
# Certificados SSL
# NOTA: Debes generar estos certificados o usar Let's Encrypt
# Para desarrollo/pruebas locales, usa certificados autofirmados
# Para producción, usa certificados reales de Let's Encrypt o una CA
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
# Configuración SSL moderna y segura
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers off;
# HSTS (HTTP Strict Transport Security)
# Obliga al navegador a usar HTTPS por 1 año
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Seguridad adicional
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
# Sesión SSL
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
# Logs
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Frontend - Servir archivos estáticos de React
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# API Backend - Proxy al backend Django
location /api/ {
proxy_pass http://backend;
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 https;
proxy_set_header X-Forwarded-Ssl on;
proxy_redirect off;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Admin de Django
location /admin/ {
proxy_pass http://backend;
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 https;
proxy_set_header X-Forwarded-Ssl on;
proxy_redirect off;
# Timeouts extendidos para importaciones/exportaciones de archivos grandes
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Archivos estáticos de Django
location /static/ {
alias /app/staticfiles/;
expires 30d;
add_header Cache-Control "public, immutable";
}
# Archivos media de Django
location /media/ {
alias /app/media/;
expires 30d;
add_header Cache-Control "public";
}
# Configuración de gzip
gzip on;
gzip_vary on;
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/rss+xml font/truetype font/opentype
application/vnd.ms-fontobject image/svg+xml;
}