server { listen 80; server_name localhost; # La root punta a public/ di Laravel, NON alla root del progetto. # Motivo: public/ è l'unica cartella esposta al web. # Il resto del codice (app/, config/, .env…) è fuori dalla webroot = sicuro. root /var/www/public; index index.php index.html; # Charset e log charset utf-8; access_log /var/log/nginx/portale_access.log; error_log /var/log/nginx/portale_error.log; # Dimensione massima upload (per allegati cliente, loghi, ecc.) client_max_body_size 50M; # ───────────────────────────────────────────────────────────── # Regola principale: "try_files" # Per ogni richiesta, Nginx prova nell'ordine: # 1. $uri → cerca il file esatto (es. /css/app.css) # 2. $uri/ → cerca come directory # 3. /index.php?$query_string → passa tutto a Laravel (front controller) # ───────────────────────────────────────────────────────────── location / { try_files $uri $uri/ /index.php?$query_string; } # ───────────────────────────────────────────────────────────── # Gestione file PHP: passa le richieste a PHP-FPM # "app:9000" → nome del container PHP nel docker-compose + porta FPM # ───────────────────────────────────────────────────────────── location ~ \.php$ { fastcgi_pass app:9000; fastcgi_index index.php; # SCRIPT_FILENAME: percorso assoluto del file PHP da eseguire fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; # Timeout generosi per operazioni lunghe (import, report, ecc.) fastcgi_read_timeout 300; } # ───────────────────────────────────────────────────────────── # Blocca accesso ai file nascosti (es. .env, .git, .htaccess) # IMPORTANTE: non esporre mai il .env al web! # ───────────────────────────────────────────────────────────── location ~ /\.(?!well-known).* { deny all; } # Cache browser per asset statici (performance) location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } }