Non-existing Subdomains/Vhosts point to first site created.

Hello all, I've got a weird issue, well it's probably a logical thing.. but still.

I'm running CentOS atm, with Webmin/Virtualmin. I've added some sites via the Linode DNS manager, including a subdomain. And if I don't add them via Virtualmin to get their own site, it just loads whatever site I first created.

http://firstdomain.com -> loads /home/firstdomain

https://firstdomain.com -> loads /home/firstdomain

http://noneexistingsub.firstdomain -> loads /home/firstdomain

http://noneexistingdomain.com -> loads /home/firstdomain

http://existingdomain.com -> loads /home/existingdomain

http://noneexistingsub.existingdomain.com -> loads /home/firstdomain

https://existingdomain.com -> loads /home/firstdomain (can only have SSL on one Vhost enabled?)

For a while I had wildcard subdomains enabled on some domains, but this caused 'whatever.existingsubdomain.com' to load the first domain as well.

Is there anything I should adjust?

I've tried VHCS as well on a clean Debian install, to see how it would handle it.

Oh and btw, do I need to run BIND9 on my server as well? Since it doesn't seem to make a difference wether I do or don't at this point.

Thanks for your advice, this is my first 'real' VPS/DS :)

4 Replies

> And if I don't add them via Virtualmin to get their own site, it just loads whatever site I first created.

To me that sounds like normal behavior, except one thing I'll mention shortly.

The Linode DNS Manager does not configure your virtual hosts for you; all it does is tell the world that anybody interested in yourdomain.com should look for it in your server. Now if anyone actually wants to connect to yourdomain.com, it's your server's job to decide which files to send to which visitor. Virtualmin helps you configure your server in the right way. You tell Virtualmin which domains/subdomains should be served from which directory. Virtualmin translates your directives to a format which the Apache web server understands. Apache then sends files from the right directory to the right visitor.

Which means that you must configure all of your domains/subdomains in both the DNS Manager and in Virtualmin. This is a big difference between shared hosting solutions such as cPanel and a VPS. cPanel sets up everything automatically so you only need to set up your domains/subdomains once. Here you must set them up at least in two different locations.

The important thing to remember is that subdomains don't automatically point to the main domain (or its subdirectory) like they do in cPanel. You must go to Services - Configure Websites - Networking and Addresses, and list all your subdomains under "Alternative virtual server names". You even have to list yourdomain.com and www.yourdomain.com separately. Otherwise they're treated as completely different domains.

Note: You might be able to setup wildcard subdomains (*.yourdomain.com) to catch all your nonexistent subdomains, but I've never used that option so I'm not sure if it'll work.

So it is only to be expected that, if you don't add a site to Virtualmin, it won't be served properly. Your server simply doesn't know which files to serve! So depending on how other things are configured, either the default page, or an error message, or some other site will be served. It seems that you've got the last of these three cases.

Now, here's the one problem I said I would mention. You've got the third of the three scenarios I just talked about, and this is not normal. Usually, when Apache can't decide where to serve a domain/subdomain, it'll serve a file from the default directory, not from a directory that belongs to another site. So you should check if the default directory is configured properly. Go to Webmin - Apache server, and look for a server named default in the "Virtual hosts" page. Note the "document root" directory associated with the default server. Is it the same as the document root of your first site? Or is the first site actually the default?

> do I need to run BIND9 on my server as well?

In my opinion you should avoid running your own DNS server unless you absolutely have to. First of all, Linode DNS Manager does the job very well. Second, you'll have to register 2 of your own nameservers with your domain registrar, and many of them will refuse to accept that unless you have 2 different IP addresses. Most importantly, it's just too much hassle to run your own DNS server (one more service to look after = one more headache), and something is probably going to go wrong especially since you're new to the VPS scene.

Hope this helps,

Thanks so much for your reply!

I understand the DNS stuff yeah, that I need to configure both sides.. also thank you for the note on the subdomains in virtualmin.

I'd like for the non-configured sites to show a default page, or just an error message.

I've checked the Webmin page for Apache. And it shows this for the default one :

Type Address Port Server Name Document Root URL

Default Server Any Any Automatic /var/www/html Open..

The rest of the sites are listed with address set to the WAN IP, port 80 and one with 443 for the one with

ssl enabled. Server names for their domain names and doc roots all /home//public_html.

The way it should apparently..

root@serv www]# ls
awstats  cgi-bin  error  html  icons  manual  usage
[root@serv www]# cd html
[root@serv html]# ls
[root@serv html]# 

I've also tried creating an index.html / index.php file in the html dir, but it won't show up when I go to a non-configured domain. Also, I've tried http:// and it shows the first configured site as well. And https:// shows the first (and only) ssl configured site, instead of an error message of

some sort..

It's Apache version 2.2.3 btw, don't know if it would matter..

Again, thanks alot.. I figured this behavior wasn't normal.

Your default server is set to listen to any address and any port, whereas all your "real" sites are configured with particular addresses and port numbers. I'm not exactly sure how Virtualmin & Apache on CentOS handles this (there are always little differences that are hard to pinpoint…) but you might be suffering something like the "port mixing" problem that's described in the following post:

http://www.linode.com/forums/viewtopic.php?t=3275 (That post is actually about a very similar problem.)

I've also had the same problem before, and it was all about little details like port numbers and the like. If you still can't get it to work, delete all your virtual hosts (after you backup the data), adjust settings for the default host, and try to add the virtual hosts again.

By the way, if you chose Virtualmin just because that's what everyone is talking about, I'd suggest you try out ISPConfig (http://www.ispconfig.com). In what little experience I have, it's many times more intuitive than Virtualmin and it also handles virtual hosts much better. It lacks some features of course, but nothing too important. It's also got a pretty active community, and the online documentation even comes with a "perfect setup" tutorial for every major linux distro including CentOS, OpenSUSE, Debian, and the currently-popular Ubuntu. If you follow the tutorial, everything from virtual hosts to email should work out of the box. Just remember to stop the DNS server after you've set up everything.

I see what you mean.. I've added this manually to the httpd.conf file just now, and restarted Apache. Now it works the way it should :)

 <virtualhost xx.xx.xx.xx:80="">DocumentRoot /var/www/html
 <directory var="" www="" html="">Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All</directory></virtualhost> 

Only SSL won't work the way it should,

I tried adding this too, for the ssl connections to non-ssl domains :

 <virtualhost xx.xx.xx.xx:443="">DocumentRoot /var/www/html
 <directory var="" www="" html="">Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All</directory></virtualhost> 

Which is wrong, since this entry will override the other one I have.

The other domains show the right error now at least, "can't open cause it couldn’t establish a secure connection to the server". Only the domain with the SSL enabled doesn't work anymore. Should I add a block like that for each domain, a virtualhost with port 443 I mean? Guess it would solve my issue but there's probably a better way to do it?

And yes, I looked around for various control panels, came across Webmin/Virtualmin, VHCS and ISPConfig as well. I first was doing everything manually, but it was a bit too much work and didn't really know how to configure postfix so decided to look for a CP.

I'll boot another distro and start on ISPConfig now, see how that feels :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct