You can't: the web server has to accept the connection to know the hostname. The best you can do is close the connection immediately without sending a response if it's an unknown hostname.
I believe that at least with Apache and nginx doing this requires using a non-default module.