Subdomains

Hi guys,

I'm looking into setting up subdomains on my site & was really after some pointers.

Can I just edit apache's config to point the subdomain to a set directory or will I need to mess about with DNS?

Apologies for the noob posting!

Fully.

11 Replies

Hi,

You will need to set another vhost is the apache conf file and then add an A record to the DNS record.

Adam

You need to do a little messing with DNS.

If you don't really know too much about DNS, check to see if your registrar supports subdomains .. or your current domain name service provider supports them. (like a web-interface or something)

If they don't, transfer your DNS to zoneedit.com (great and free), and then can easily deal with subdomains and such.

Basically you need to create a subdomain and point it to an IP.

After you have done such, you need to setup apache to deal with subdomains (the following is an example)

#
# Use name-based virtual hosting.
#
NameVirtualHost 12.13.14.15

 <virtualhost 12.13.14.15="">ServerAdmin webmaster@domain.com
        DocumentRoot /usr/www/htdocs
        ServerName sub.domain.com
        ServerAlias www.sub.domain.com
        ErrorLog /usr/www/logs/error_log
        CustomLog /usr/www/logs/access_log common
        UserDir enabled jack
        # this would be for something like http://sub.domain.com/~jack</virtualhost> 

HTH

Sunny Dubey

As for the DNS side of things depending on who your DNS is through you can most likely set a wildcard record. This points *.yourdomain.com at your Linode's IP. That way when you need to add another virtual host in the furture, you just edit the apache config, restart it and you are in business.

Linode has reverse dns which great on your page. Just point it to your domain after you point your domain to your linode ip

I am missing the connection between reverse dns and subdomains.

There is none, but Linode rocks just for having such a feature.

-Chris

caker indeed!

Thanks for all the advice guys. Looks like the * bit in my dns was all I needed :D

Weird how I didn't use that in the Cpanel account I run yet subdomains came online instantly.. sounds like Voodoo to me :)

Thanks again.

Fully

There is one thing to watch out for when using wild card domain names. Whatever is your first virtual host becomes your defualt virtual host.

Meaning if I were to go to: kjsht5.domain.com or w24ksrg.domain.com I will get the first virtual host apache is serving up.

Therefore it is suggested that first virtual host be a dummy virtual host, which an error of "Domain not configured" or something similar. httpd -S will show you how your virtual hosts are configured.

Sunny Dubey

I was given the idea the using the reverse dns is what gives you the vhost. I tried it and looks like it works on my psybnc. I would think it would be the samething as virual host.

I maybe off base. Just trying offer alittle bit help back to you guys.

Sorry if i wrong giving out bad advise(my bust).

You seem to have gotten mixed up somehow about the relationship between DNS, Reverse DNS, and web server virtual hosts.

First of all, know that Reverse DNS lookups are a specific kind of DNS lookup, and that they have absolutely nothing to do with making web server vhosts work. I'll explain more about what they are good for at the end.

You can configure your web server with all the vhosts you want. A vhost for www.yourdomain.com, a vhost for www.linode.com, a vhost for ha.ha.ha.ha……. but no web browser will ever see those websites unless those names 1) exist in DNS and 2) resolve to your server's IP address.

Right now, let's pretend that I have my web server configured with a vhost for www.linode.com. What happens you enter http://www.linode.com/ into your browser? Your browser looks up that name and connects to that server, and guess what… it's not my server. The name does not resolve to my IP address.

Right now, I actually do have a vhost for http://state.gov.zz/. Try clicking on that link. What happens? Nothing, because your browser cannot resolve that name. As far as your web browser knows, it doesn't exist.

So in order for web browsers to find your web server, the name has to exist in DNS, and it has to resolve to your IP address. Once that's all set, your web server will actually receive connections when people enter the name into their browsers.

Now let's look at the opposite situation. Let's say you've got DNS all set up, and your web server is running, but you don't have a vhost for the name. What happens when a browser requests something from that website? Your web server has to send something, so what it does is it searches the list of vhosts, finds that none match, and then goes back to the first one on the list and serves the content from that vhost. That's why people like me always create a default vhost and put it first in the configuration, and then create subsequent vhosts for each real domain that the server is supposed to serve.

Basically, in order for a web server virtual host to work, both need to be set up.

Now, Reverse DNS is a different business. It's generally only used for logging or displaying client connections. For example, if you were to run a web browser on your linode and connect to my web server, my web server would have your IP address. However, my web server will try to do a reverse lookup to get the hostname, so that it can write that to the log instead of the IP address. The same sort of thing happens when you connect to IRC. The IRC server does a reverse lookup to get your hostname as uses that in your hostmask instead of the IP address. Having reverse DNS set to your own hostname vs. the default generally doesn't actually make anything work any differently. There are exceptions, but you can safely ignore them.

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