# Configuration Nginx pour le Portfolio
# À adapter selon votre serveur

server {
    listen 80;
    server_name monportfolio.fr www.monportfolio.fr;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name monportfolio.fr www.monportfolio.fr;

    # SSL - À adapter selon votre configuration Let's Encrypt
    ssl_certificate /etc/letsencrypt/live/monportfolio.fr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/monportfolio.fr/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    root /var/www/portfolio;
    index index.php;
    charset utf-8;

    # Headers de sécurité
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "DENY" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    # Bloquer fichiers sensibles
    location ~ /\.(env|git|htaccess) { deny all; return 404; }
    location ^~ /vendor/ { deny all; return 404; }
    location ^~ /node_modules/ { deny all; return 404; }
    location ^~ /logs/ { deny all; return 404; }
    location ^~ /data/ { deny all; return 404; }
    location ^~ /includes/ { deny all; return 404; }

    # Assets statiques avec cache long
    location /assets/ {
        expires 1y;
        add_header Cache-Control "public, immutable";
        gzip_static on;
    }

    # Router PHP (front controller)
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # PHP-FPM - À adapter selon votre version PHP
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml;
}
