Subdomain, what am I missing?

Trying to get subdomains working. I have DNS set up in Linode for my domain itsbetterintheoven.com, for sub.itsbetterintheoven.com. It's set up to go to the main IP address, and shows up as doing so:

host sub.itsbetterintheoven.com

shows 72.14.188.138, as it should.

On the server side, in addition to my file for the main domain, I have sub.itsbetterintheoven.com with the following information:

 <virtualhost 72.14.188.138:80="">ServerAdmin myemail@address.com
  ServerName sub.itsbetterintheoven.com
  ServerAlias www.sub.itsbetterintheoven.com
  DocumentRoot /srv/www/sub.itsbetterintheoven.com/public_html
  ErrorLog /srv/www/sub.itsbetterintheoven.com/logs/error.log
  CustomLog /srv/www/itsbetterintheoven.com/logs/access.log combined</virtualhost> 

I've run a2ensite on the file, and I've restarted apache. What gives?

10 Replies

>.>

You seem to be confusing IP-based virtualhosts with name-based virtualhosts… which happens often, for they're counterintuitive.

IP-based vhosts:

 <virtualhost 1.1.1.1:80="">ServerAdmin myemail@address.com 
  ServerName example.com 
  ServerAlias www.example.com 
  # DocumentRoot, logs, whatever</virtualhost> 
 <virtualhost 2.2.2.2:80="">ServerAdmin myemail@address.com 
  ServerName sub.example.com 
  ServerAlias www.sub.example.com 
  # DocumentRoot, logs, whatever</virtualhost> 

Name-based vhosts

NameVirtualHost *:80
 <virtualhost *:80=""># First namevhost for this IP(or wildcard), will be selected
  # if the user agent did not supplied Host: header
  ServerAdmin myemail@address.com 
  ServerName example.com 
  ServerAlias www.example.com 
  # DocumentRoot, logs, whatever</virtualhost> 
 <virtualhost *:80="">ServerAdmin myemail@address.com 
  ServerName sub.example.com 
  ServerAlias www.sub.example.com 
  # DocumentRoot, logs, whatever</virtualhost> 

Or, instead of *:80 you can specify one, and the same IP for a name vhost group, so you can have some namevhosts at one IP, and others at other. Matching there is done one the ServerName and ServerAlias lines.

Creating a ServerAlias doesn't do enough. All it does is tell Apache to recognize the new domain/sub-domain. In order for people to actually be able to find it, you still have to add it to DNS.

I had already done that though. I tried it two ways: creating a new domain zone for my subdomain through Linode's manager, and when that didn't work added a new A record for the subdomain, pointing to the IP address, through the DNS zone for the main domain.

The IP address that I listed above was simply to regard that my subdomain seemed to be pointing to the correct IP address.

a2ensite sub.domain.com && /etc/init.d/apache2 restart

freedomischaos… already did that. No joy. I'm stumped. I've double checked all of my spellings in my files, but it just doesn't want to show up.

````
kmw@charliebrown:~$ dig www.sub.itsbetterintheoven.com

; <<>> DiG 9.4.3-P4 <<>> www.sub.itsbetterintheoven.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 52181
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;www.sub.itsbetterintheoven.com. IN A

;; AUTHORITY SECTION:
itsbetterintheoven.com. 86378 IN SOA ns1.linode.com. kenneth.tdpowerskills.com. 2010021171 14400 14400 1209600 86400

;; Query time: 1 msec
;; SERVER: 74.207.241.5#53(74.207.241.5)
;; WHEN: Mon Feb 15 17:10:40 2010
;; MSG SIZE rcvd: 117

````

Note that there's no "ANSWER SECTION"; this is because www.sub.itsbetterintheoven.com does not actually exist in DNS. Are you sure you've got it configured correctly?

Now, sub.itsbetterintheoven.com does work, as does www.itsbetterintheoven. Are sure that www.sub.itsbetterintheoven.com is what you actually wanted?

Not to hijack this thread, but I'm also having a similar issue with subdomain. Set A record in DNS, set VirtualHost, linked sites-available to sites-enabled, restarted Apache, etc.

To the OP: was this ever resolved?

EDIT: Ok, I got mine fixed. I realized I was supposed to be using a "CNAME" record instead of an "A" record. D'oh! Maybe this will help out.

I'm having the same issue and I've followed the same steps as the OP and bdl. I followed this guide http://davidpodley.com/2010/02/11/setti … nd-apache/">http://davidpodley.com/2010/02/11/setting-up-subdomains-in-linode-and-apache/ which suggests setting an A record for the subdomain. But, bdl, you say that you did it with a cname? What exactly did you use for your cname?

I tried setting a cname with a host name of "radiant" aliased to "bobby-marko.com" and that didn't work so I tried aliasing "radiant" to "radiant.bobby-marko.com" and that didn't work either. My original attempts were with the A record host name set to "radiant" and the IP address set to my Linode IP.

What am I doing wrong?

Here's my main domain virtual host:

 <virtualhost 74.207.233.205:80="">ServerAdmin xxxx@xxxx.com
     ServerName bobby-marko.com
     ServerAlias www.bobby-marko.com
     DocumentRoot /srv/www/bobby-marko.com/public_html/
     ErrorLog /srv/www/bobby-marko.com/logs/error.log
     CustomLog /srv/www/bobby-marko.com/logs/access.log combined</virtualhost> 

and my sub domain:

 <virtualhost 74.207.233.205:80="">ServerName radiant.bobby-marko.com
    ServerAlias *.radiant.bobby-marko.com
    DocumentRoot /srv/www/radiant.bobby-marko.com/public/
    <directory srv="" www="" radiant.bobby-marko.com="" public="">Allow from all
        Options -MultiViews</directory></virtualhost> 

Sorry if I'm making some huge mistake somewhere, I'm new to all of this. I also tried disabling the default site virtual domain file and I saw no change so I enabled it again.

Thanks

-Bobby

It does not matter to HTTP whether you use CNAME or A/AAAA records, as long as they lead to the correct destination in the end.

Regarding your actual issues, I don't know Apache, and I've got no idea. :D

The subdomain started working this morning. I think it just took a while for the dns to propagate.

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