server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; server_tokens off; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; # gzip gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; # Redirects relativos (preserva el puerto del proxy) absolute_redirect off; port_in_redirect off; # Soporte WebP condicional (sirve .webp si existe y el cliente lo acepta) location ~* ^(.+)\.(png|jpg|jpeg)$ { add_header Vary Accept; try_files $1.webp $uri =404; expires max; } # Cache largo para assets con hash (Astro los hashea en _astro/) location /_astro/ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff2?)$ { expires max; log_not_found off; access_log off; try_files $uri =404; } # === Handler del formulario de contacto === # Único archivo PHP del sitio. Lo rutea al contenedor php-fpm. location = /enviar.php { # Evitar ejecución de otros .php por seguridad limit_except POST { deny all; } include fastcgi_params; fastcgi_pass acopladosbelensa_mail:9000; fastcgi_index enviar.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto; fastcgi_hide_header X-Powered-By; } # Bloquear cualquier otro archivo .php (defensa en profundidad) location ~ \.php$ { deny all; } # Bloquear archivos ocultos location ~ /\. { deny all; access_log off; log_not_found off; } # Sitio estático: fallback a index.html location / { try_files $uri $uri/ /index.html; } }