3 ms·
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
by Denvercoder9 6y ago
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.
- icedchai 6y agoI think you are over complicating things. You just need a default virtual host that displays a "domain not configured" page. This is what we did when I ran a hosting company.
- Denvercoder9 6y agoThe parent comment originally said "just don't accept HTTP connections for unknown hostnames".
- susam 6y agoIndeed the web server has to accept the connection, check the hostname, and return an error or close the connection without response.