1

I am using Apache 2.2 on a Debian-based distro. For some reason, all URLs are directed to the default index. No error or anything. That means: example.domain.com goes to domain.com. "example" can be just anything. In the default Vhost file (/etc/apache2/sites-available/default) I've added:

ServerName: www.domain.com

But it still keeps that odd behaviour. Please let me know how to enable the common, default behaviour. I haven't changed anything by the way, this is since installation.

Update: Following SvW's answer, I am looking for a way to force Apache not to accept any URL, only those specified as VirtualHosts.

Ariel
  • 113
  • 4
  • How do you want Apache to react if an undefined server name is used? – Sven May 31 '14 at 13:50
  • See [How to make undefined host go to default Page in apache2 virtual hosts](http://serverfault.com/questions/521011/how-to-make-undefined-host-go-to-default-page-in-apache2-virtual-hosts). I.e. just define a vhost that goes nowhere _first_. – AD7six May 31 '14 at 14:01

2 Answers2

2

Any request which does not match a specific vhost will be sent to the default vhost by Apache.

The solution I recommend is to create a default vhost before all the "real" ones. This default vhost should not match any of your domains, and should reply with an error code on every request. I think 404 would be an appropriate answer from this vhost.

kasperd
  • 30,455
  • 17
  • 76
  • 124
1

The primary "problem" is that you have a wildcard DNS entry pointing to your web server, otherwise you would get an "unknown host" error from your browser. Remove that and this will stop (after the TTL of the entries is expired, up to 24h hours later).

Apache itself will always use the first vhost definition to answer requests for host names not defined in other vhosts.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • I am using DDNS, and I the provider doesn't let me control DNS entries. Is there a way to tell Apache to ignore any prefixes not defined? – Ariel May 31 '14 at 13:09
  • 2
    Not that I know of. You could write a special first vhost that does nothing else than to either throw an error or redirect requests to your real site. In my opinion, the solution is to switch to a provider that lets you control the domain that *you* own. – Sven May 31 '14 at 13:11