server {
    listen 80;
    server_name localhost;
    root /var/www/html/public;
    index index.php index.html index.htm;

    charset utf-8;

    # Logs
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Tamanho máximo de upload
    client_max_body_size 100M;

    # Laravel - redirecionar todas as requisições para index.php
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # PHP-FPM
    location ~ \.php$ {
        fastcgi_pass app:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
        fastcgi_read_timeout 300;
    }

    # Negar acesso a arquivos ocultos
    location ~ /\.(?!well-known).* {
        deny all;
    }

    # Negar acesso a arquivos sensíveis
    location ~ ^/(\.env|\.git|composer\.(json|lock)|package(-lock)?\.json|webpack\.mix\.js|artisan|storage|bootstrap/cache) {
        deny all;
    }

    # Cache para assets estáticos
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
        access_log off;
    }
}
