-2

I have NameVirtualHost *:80 in ports.conf and a VirtualHost who has ServerName www.mysite.com in my conf file. I also have few subdomains mapped to other VirtualHosts.

Currently if I access mysite.com with some arbitrarily picked subdomain that is not configured as a subdomain in my config file, it redirects to the one with www.. For example, if i try nowhere.mysite.com it goes to www.mysite.com.

I don't think this is normal behavior on a web site. How can I ignore all requests that does not go to any proper domain?

2 Answers 2

4

Well, first, the fact that those names resolve at all instead of kicking the user back an error with name resolution implies that you've configured a wildcard in your DNS zone (*.mysite.com.). If you want lookups to bogus subdomains to fail, get rid of that.

On a name-based virtual host, the first virtual host to load on the address:port combination is treated as the default, and handles all requests for hostnames that aren't configured. You can see how this shakes out for your installation with apachectl -S.

Apache will never send a redirect 30x response putting the user on a different domain name unless it's configured to do so - the redirecting behavior you're seeing is either explicitly configured or being generated by the application running on your web server. Normally, you'd just be getting content served by the default virtual host, not getting redirected to its canonical name.

If you don't want to get rid of the wildcard DNS but do want to serve up errors for these requests, then change the load order of your virtual hosts to have the default be something like this:

<VirtualHost *:80>
  ServerName catchall
  <Location />
    Order allow,deny
    Deny from all
  </Location>
</VirtualHost>
5
  • It seems like I cant use Order in VirtualHost
    – thkang
    Aug 18, 2013 at 20:21
  • @thkang You're right, my mistake. Fixed. Aug 18, 2013 at 20:26
  • okay, so it seems like I have a wildcard in my DNS, through my domain registrar - and it have to be kept that way. the <Location> tags were kinda meaningless because apache is just a middlemen between wsgi and user, as I have a WSGIScriptAlias sitting on /. But thanks for your help anyway.
    – thkang
    Aug 18, 2013 at 20:37
  • @thkang So then your WSGIScriptAlias configuration is global? If you don't want that active for all virtual hosts, then move it to within the virtual hosts you want it to be active for. Aug 18, 2013 at 20:38
  • nah, WSGIScriptAlias is on the first VirtualHost whose servername is www.mysite.com
    – thkang
    Aug 18, 2013 at 20:40
3

If the domain www.mysite.com is the first domain defined in your configuration then this is entirely normal. If Apache cannot match the domain in the Host: header to a virtual host ServerName or ServerAlias it will serve the contents of the default domain which unless otherwise defined is the first one.

You should probably read the documentation it is immensely helpful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .