1

In our office, we have a public facing server whose machine hostname is server16. We want Apache to only respond to requests on server.example.com. We have a VirtualHost entry with ServerName server.example.com. The problem is, if we include a VirtualHost entry for server16.example.com, then apache responds to it, so we have it respond with 403: Forbidden, but we would like it to not accept a request to server16.example.com at all.

We have talked with our system admins, and for certain reasons, we can't change the hostname of the server. Is there anyway within Apache to do what we need?

1

What you are asking is not possible at the web server level. The server does not know what host name is requested until after it has accepted the connection. Here is what happens when you request a URL such as server.example.com or server16.example.com:

  1. The client looks up the IP address for the host name. In either case, it will get the same IP address.
  2. The client opens a connection to that IP address on port 80.
  3. The client sends the request which includes the document path and the host name. In its simplest for it looks like:

    GET / HTTP/1.1
    Host: domain.example.com
    
  4. The server decides what HTTP response to send based on its configuration.

Configuring the server to respond with "403 Forbidden" is perfectly acceptable. I would say that a "404 Not Found" would be more appropriate because the server doesn't have any documents for that domain.

The only way to prevent the connection altogether would be for server16.example.com to be removed from DNS. If that DNS were removed, then a connection for that domain name would not be able to be established.

|improve this answer|||||
  • Thanks! We ended up convincing our sysadmins to change the DNS record for our machine. – dallpickle343 Feb 14 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.