Why does Apache2 serve a subdomain when given an IP?
March 14, 2009 12:41 AM   Subscribe

I have a domain hosted on a VPS running CentOS5. Whenever I enter http://my-vps-ip in my browser, I get redirected to http://subdomain.mysite.com. My limited Google-fu is no match for this particular problem, so I'm hoping the folks at AskMeFi can tell me how I should setup Apache so that http://my-vps-ip goes to http://mysite.com and not the subdomain?

Extracts from the httpd.conf file:
ServerName mysite.com
...
UseCanonicalName Off
conf file defining the subdomain:
<virtualhost *:80> 
        ServerName      subdomain.mysite.com
        DocumentRoot    /var/www/subdomain
        ErrorLog /var/log/httpd/subdomain_mysite_com-error.log
        CustomLog /var/log/httpd/subdomain_mysite-access.log combined
    <directory> 
        Options Indexes FollowSymLinks
        AllowOverride AuthConfig FileInfo Indexes Limit
       Order allow,deny
       Allow from all
     </directory> 
< /virtualhost> 
Also, FWIW - currently the rDNS lookup on my VPS IP goes to ns1.mysite.com.

Many thanks!
posted by your mildly obsessive average geek to Computers & Internet (4 answers total)
 
Response by poster: hades - I already have the following virtual host entries setup at the end of my primary httpd.conf:
#Virtual Host for main server
<VirtualHost *:80>
ServerName www.mysite.com
ServerAdmin webmaster@mysite.com
DocumentRoot /var/www/html
ErrorLog /var/log/httpd/mysite_com-error.log
CustomLog /var/log/httpd/mysite-access.log combined
</VirtualHost>

#Virtual Host to handle non www requests
<VirtualHost *:80>
ServerName mysite.com
ServerAdmin webmaster@mysite.com
DocumentRoot /var/www/html
ErrorLog /var/log/httpd/mysite_com-error.log
CustomLog /var/log/httpd/mysite-access.log combined
</VirtualHost>
Am I correct in understanding that the entries in my virtual hosts conf file is overriding these entries? So if I were to move these to the top of my virtual hosts conf file - Apache should stop serving subdomain.mysite.com for the VPS IP?
posted by your mildly obsessive average geek at 2:42 AM on March 14, 2009


Yes, that's the normal setup.
posted by ArkhanJG at 9:39 AM on March 14, 2009


Also, you can use _default_ so that you don't have to pay attention to the order of your vhosts.
posted by rhizome at 10:25 AM on March 14, 2009


Response by poster: I tried adding the _default_ option to the Virtual Host entry in the httpd.conf but I think the "Include conf.d/*.conf line" is still taking precedence.

In any case, I moved the Virtual Host entry for mysite.com to the same conf file as the sub-domain and added the _default_ option. After that, it started working!

hades - thanks for the tip on the ServerAlias.
posted by your mildly obsessive average geek at 2:51 AM on March 15, 2009


« Older Ski boot stiffness index   |   Where to relocate to a warm area with mountains? Newer »
This thread is closed to new comments.