I am not entirely certain which scenario, of those below, you are looking for, but both are easy to accomplish. Specifying '404 if nothing exists' shouldn't be necessary as that is the default behaviour of nginx anyway (although, you can customize the error page if you want).
Scenario 1: redirect all subdomains to the SAME folder:
server {
server_name *.mysite.com;
root /var/www/mysite/subdomaindir/;
...your other blocks/directives
}
Scenario 2: redirect all subdomains, each to their own folder:
server {
server_name ~^(?<sub>.+)\.mysite\.com$;
root /var/www/mysite/subdomaindir/$sub;
...your other blocks/directives
}