server {
    listen 80;
    server_name your-domain.com;

    root /var/www/testing-tool/web/public;
    index index.php;

    # Deny access to sensitive files
    location ~* \.(env|log|sh|sql)$ {
        deny all;
        return 403;
    }

    # Deny access to hidden files
    location ~ /\. {
        deny all;
        return 403;
    }

    # Front controller
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        # Increase timeout for long-running SSE connections
        fastcgi_read_timeout 3600;

        # Disable buffering for SSE
        fastcgi_buffering off;
    }

    # Security headers
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-XSS-Protection "1; mode=block";
    add_header Referrer-Policy strict-origin-when-cross-origin;
}
