Apache2 is serving single NameVirtualHost for all names
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Apache2 is serving single NameVirtualHost for all names
Hi,
I have an Apache2 server running on Debian Etch. I want to get rid of the default website... so that if someone surfs to the machine via some domain name I have NOT yet configured, the Apache server will return a "document not found" error.
I have configured one single file in /etc/apache2/sites-available to run as a virtual host. I have enabled this file (the link is in sites-enabled) and I have also DISABLED the 000-default file. When I run my server and point to the proper virtual host name (www.mydomain.com ,which was configured for in the single virtual host file mentioned earlier), Apache serves the correct file. However, if I point to first.mydomain.com or anything.mydomain.com (both which resolve to the same IP address as www.mydomain.com) then Apache serves the www.mydomain.com files... almost like it's using that virtual host name as the "default" site to serve.
Note
Note, that the "main server" and any _default_ servers will never be served for a request to a NameVirtualHost IP address (unless for some reason you specify NameVirtualHost but then don't define any VirtualHosts for that address).
How should I have my virtual host file configured so that it is NOT used as the default dropping site for other domain names that point to that same machine?
For any undefined ServerName fields, a name-based vhost defaults to the address given first in the VirtualHost statement defining the vhost.
Name-based vhost
If the entry corresponds to a name-based vhost the name list contains one or more vhost structures. This list contains the vhosts in the same order as the VirtualHost directives appear in the config file.
The first vhost on this list (the first vhost in the config file with the specified IP address) has the highest priority and catches any request to an unknown server name or a request without a Host: header field.
If the client provided a Host: header field the list is searched for a matching vhost and the first hit on a ServerName or ServerAlias is taken and the request is served from that vhost. A Host: header field can contain a port number, but Apache always matches against the real port to which the client sent the request.
If the client submitted a HTTP/1.0 request without Host: header field we don't know to what server the client tried to connect and any existing ServerPath is matched against the URI from the request. The first matching path on the list is used and the request is served from that vhost.
If no matching vhost could be found the request is served from the first vhost with a matching port number that is on the list for the IP to which the client connected (as already mentioned before).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.