DNS/Apache subdomain confusion

hi,

I have a basic question about whether my apache config is setup correctly on one of my linodes. We have a domain that is currently hosted on mediatemple but we are forwarding subdomains from that domain to linode.

So our mediatemple DNS config is like this:

A records for:

books.example.com -> [IP OF MY LINODE]
events.example.com -> [IP OF MY LINODE]

Then on the linode I don't have specific DNS entries just the following apache configs:

# /usr/sbin/apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server books.example.com (/etc/apache2/sites-enabled/books.example.com:1)
         port 80 namevhost books.example.com (/etc/apache2/sites-enabled/books.example.com:1)
         port 80 namevhost events.example.com (/etc/apache2/sites-enabled/events.example.com:1)

[ snip ... ]

Syntax OK

and my configs that are symlinked in sites-enabled:

# cat books.example.com 
 <virtualhost *:80="">ServerAdmin admin@example.com
        ServerName books.example.com
        ServerAlias books.example.com
        DocumentRoot /srv/www/books.example.com/public_html/
        ErrorLog /srv/www/books.example.com/logs/error.log
        CustomLog /srv/www/books.example.com/logs/access.log combined

        <directory>Options FollowSymLinks
                AllowOverride All</directory></virtualhost> 

# cat events.example.com 
 <virtualhost *:80="">ServerAdmin admin@example.com
        ServerName events.example.com
        ServerAlias events.example.com
        DocumentRoot /srv/www/eventssite/public_html/
        ErrorLog /srv/www/eventssite/logs/error.log
        CustomLog /srv/www/eventssite/logs/access.log combined

        <directory>Options FollowSymLinks
                AllowOverride All</directory></virtualhost> 

Now the issue is that books.example.com returns the site at events.example.com and thing generally are a little glitchy. We set up the DNS for this about 18 hours ago. Is it just DNS propagation or is my configuration incorrect?

Please advise, I don't really know that much about DNS configurations… DO I need to modify my /etc/hosts file for example?

Thanks!

  • J

3 Replies

A n00b here, but just wondering did you put both subs virtual host configs in the same file?

Not sure if this would actually cause any problems, but there's no point in having a ServerAlias directive with the same name you have as ServerName. I would remove the ServerAlias lines.

You can check DNS with dig +trace books.example.com - this will bypass your ISP's nameservers and do a lookup starting at the DNS root. Modifying your /etc/hosts only changes what your local machine sees, and probably won't be any help.

/etc/hosts can have an effect on apache virtual servers.

If your default virtual server is DocumentRoot /srv/www/books.example.com/public_html/, and events.example.com is in the hosts file to resolve to the IP address of the server, then apache fails to pick up on the fact that the request comes from events.example.com and instead assumes it was a request made directly to the IP address of the server, which causes it to use the default virtual site.

You may wish to remove events.example.com from /etc/hosts if it is in there, and see if this makes a difference. If nothing I have said makes sense, it may be useful to paste us the hosts file.

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