Redirect arbitrary sub-domains to custom 404 when wild card A record is set?

Is there a way to capture all requests to sub-domains which do not have
a virtual host setup, and redirect to a custom 404 page? I will have a
wild card A record setup *.example.com and all our users will have a
sub-domain username.example.com. If someone enters a sub-domain which
does not exist how can I redirect to a custom 404 page rather than have
it resolve since wild card is setup?

Thanks

Posted at Nginx Forum:

On Sun, Nov 20, 2011 at 03:59:13PM -0500, anagio wrote:

Hi there,

Is there a way to capture all requests to sub-domains which do not have
a virtual host setup, and redirect to a custom 404 page?

That’s called the default server.

http://nginx.org/en/docs/http/request_processing.html

In that server, you can redirect or respond any way you choose.

f

Francis D. [email protected]