Subdomains

I’m having some trouble setting up subdomains.

Here’s what I’ve got going on.

I run a single webserver, with a single ethernet interface, a single IP address. Linux, with Apache2.

I’ve got a website going, domain.tld

No problems there.

I want to run sub.domain.tld on the same server, but I’m a little bit confused.

Here is my sites-available in apache:

NameVirtualHost *

<VirtualHost *>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /domain
</VirtualHost>

<VirtualHost *>
ServerName sub.domain.tld
Document /domain/subdomain
</VirtualHost>

Now, I’ve got the DNS entries for domain.tld and sub.domain.tld both pointing to the same IP address (my webserver)… with the vhosts setup as above, the webserver is supposed to be able to determine which site the user is trying to access via information in the request, right?

But that’s not happening.

If I navigate to domain.tld.

So it feels to me that I’m doing something wrong with wildcards, or else I have to point the DNS to something different.

Anyone have any suggestions?

I could workaround by just redirecting sub.domain.tld to domain.tld/subdomain, but that kinda sucks.

<VirtualHost *> ServerName sub.domain.tld Document /domain/subdomain </VirtualHost>

Should be DocumentRoot.

Is the sites-available linked to sites-enabled? 

You reloaded Apache?

DNS for both sites should point to the same IP.

Yeah, that is DocumentRoot.

I’ve got sites-enabled/default linked to sites-available/default (default is the text file)… there’s really no difference to having each vhost in a separate file is, there?

And I’ve restarted apache repeatedly :wink:

So how’s the DNS set up?

If you nslookup each of them, do you get the same result?

I think that’s the ticket - I was just jumping the gun.

So far one of the subdomains resolves properly now, I think the DNS changes just needed to propogate.

I changed all of the DNS settings to an “A” record to an IP address - before, they were just being forwarded. I’m not sure how it is really different, but it is.

Updates on my end should be automatic, shouldn’t they?

Like once a subdomain is pointed at my IP address, I can just change my virtualhost’s target, reload the config, and the change should be live?

I wonder if it would be easier to get my domain registrar to forward *.domain.tld to me, and run my own DNS server…

Shouldn’t take more than an hour, tops.  Is it still not resolving?

They’re (mostly) resolving now.

Aside from a few issues with 1and1.com DNS management stuff, everything is working fairly well now.

If you’re having problems with 1&1 dns not working, just ask them to “reset” your account.  It refreshes everything.  Happened to me with a couple of clients.

Everything is working well now, thanks for your help MiG.

Follow-up question:

Now that I’m segregating my sites by subdomain, I’m out of subdomains!

My cheapo domain-registration only package at 1and1.com only gives me 5 subdomains - is this common practice, or are there free methods to get unlimited subdomains out there? I read somewhere that GoDaddy.com gives you unlimited subdomains.

That sucks.  I don’t know… can you delegate your DNS to somebody else?  If so, then you could create all the sub-domains you wanted.  For free.

I use everydns.net/ for a couple of clients, and it just lets me create as many as I want.  At least I think so … I haven’t run into any limits.

Hmm, the 1and1 control panel will let me use a different set of nameservers (I can input whatever I want)…

But if I point domain.tld at a different nameserver, will that new nameserver also have control of sub.domain.tld and all the other possible subdomains?

What would really rock for me, is if I could have *.domain.tld all routed my way, and then have my server determine the routing. Like foo.domain.tld goes to this location, foo2.domain.tld goes to another location, and www.domain.tld, and anythingelseyoucanpossiblythinkof.domain.tld goes to the default location.

Yeah, that’s wildcard dns, and it is possible.  Remember the anyname.isgay.com thing?

google.com/search?q=wildcard+subdomain

Hmm, it looks like everydns.net does wildcard subdomains. I may have to investigate further.

That was the exact moment in time that Internet became serious business.

Gahhh…Rick Rolled…Well played…very well played… :smile:

That, I think, even deserves a karma point…

When you see the domain name, you can’t help but click on it.