Something like this might work:
[code]
if ($host ~* (.*)\.domain\.com) {
$user = $1;
rewrite ^(.*)$ http://domain.com/file.php?=$user permanent;
}
[/code]
Note that this will not work for www.user.domain.com, although you can add that easily enough. Likewise, without a qualifier, it'll also consider www.domain.com a user and forward accordingly.