Multiple domains, multiple vhosts, different sites

I am trying to host multiple different rails apps on the same VPS using multiple domains. I am using Apache 2.2.17 on Ubuntu 10.10 using the latest version of Passenger. For Apache, I have multiple vhost files so that I can enable and disable particular sites easily without needing to comment them out or delete them. In addition, I am also using mod_rewrite so that the multiple domains that go to the same rails app appear to go to the same URL so I don't take a hit with search engines as far as duplicate content.

I believe that my DNS is setup properly. For each of the domains, I have a www subdomain as well as some site-specific sub-domains, such as blogs, etc. The issue I am seeing is that Apache appears to matching the www subdomain immediately and not examining the additional URL behind it. Changing ServerAlias does nothing. For example, using my setup, if I enter davidheartsrachel.com, I properly reach my wedding website. However, if I use www.davidheartsrachel.com, I reach my other website, my software development business. The URL is not re-written; it stays as davidheartsrachel.com instead of afewguyscoding.com.

The only way I have been able to properly get it to work is to use mod_rewrite in the primary vhost file to redirect to the wedding website vhost file (you can see that I have that in the primary vhost file, but it is commented out for purposes of this question). This doesn't seem proper to me? Should I get another IP and do IP vhosts instead of name-based vhosts?

When I execute apachectl -S, I get the following:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
         port 80 namevhost afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
         port 80 namevhost blog.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:69)
         port 80 namevhost davidheartsrachel.com (/etc/apache2/sites-enabled/davidheartsrachel.com:1)
Syntax OK

I notice that afewguyscoding.com is the default site - however, doesn't it have to do a full string match to determine the proper site?

In my /etc/hosts file, I have this:

127.0.0.1 localhost
72.14.183.14 www.afewguyscoding.com plato
#72.14.183.14 davidstites.com plato
#72.14.183.14 5280software.com plato
#72.14.183.14 milehigh-software.com plato
#72.14.183.14 milehighsoftware.org plato
#72.14.183.14 rachelanddavid.net plato
#72.14.183.14 rachelanddavidstites.com plato
#72.14.183.14 rachelanddavidwedding.com plato
72.14.183.14 www.davidheartsrachel.com plato
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

When I run hostname and hostname -f, I get the following (respectively):

# hostname
plato
# hostname -f
www.afewguyscoding.com

Primary site's vhost file

 <virtualhost *:80="">ServerAdmin [email protected]
  ServerName afewguyscoding.com
  ServerAlias davidstites.com, 5280software.com, milehigh-software.com, milehighsoftware.org
  ServerAlias www.5280software.com, www.milehigh-software.com, www.milehighsoftware.org, www.davidstites.com, www.afewguyscoding.com

  # this tells rails that it will run in production mode
  # this is for rails < 3.x
  RailsEnv production

  DocumentRoot /var/www/afewguyscoding/current/public
  DirectoryIndex index.html

  # custom log file locations
  # possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel alert
  ErrorLog  /var/www/afewguyscoding/current/log/error.log
  CustomLog /var/www/afewguyscoding/current/log/access.log combined

  # allows compression of text based mime.types
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  FileETag None

  <directory var="" www="" afewguyscoding="" current="" public="">Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all</directory> 

  <location blog="">PassengerEnabled off</location></virtualhost> 

 <virtualhost *:80="">ServerAdmin [email protected]
  ServerName blog.afewguyscoding.com

  DocumentRoot /var/www/wpress
  DirectoryIndex index.php

  <directory var="" www="" wpress="" current="" public="">Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all</directory></virtualhost> 

Wedding site's vhost file

 <virtualhost *:80="">ServerAdmin [email protected]
  ServerName davidheartsrachel.com
  ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com
  ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net

  # this tells rails that it will run in production mode
  # this is for rails < 3.x
  RailsEnv production
  # this is for rails >= 3.x
  RackEnv production

  DocumentRoot /var/www/davidheartsrachel/current/public
  DirectoryIndex index.html

  # Custom log file locations
  # Possible values include: debug, info, notice, warn, error, crit, alert and emerg,
  LogLevel alert
  ErrorLog  /var/www/davidheartsrachel/current/log/error.log
  CustomLog /var/www/davidheartsrachel/current/log/access.log combined

  # Allows compression of text based mime types
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  FileETag None

  <directory var="" www="" davidheartsrachel="" current="" public="">Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from All</directory></virtualhost> 

If you can think of any more information that might be helpful, please, ask me to post it.

Edit:

Let me try to clear this up. In the most essential form, my question is: why does going to davidheartsrachel.com takes you to www.afewguyscoding.com and davidheartsrachel.com takes you to davidheartsrachel.com based on my configuration above

Edit 2:

Here is my apache2.conf file:

#

ServerRoot "/etc/apache2"

# <ifmodule !mpm_winnt.c=""># <ifmodule !mpm_netware.c="">LockFile /var/lock/apache2/accept.lock
#</ifmodule>
#</ifmodule>

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

 <ifmodule mpm_prefork_module="">StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0</ifmodule> 

 <ifmodule mpm_worker_module="">StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0</ifmodule> 

 <ifmodule mpm_event_module="">StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0</ifmodule> 

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

 <files ~="" "^\.ht"="">Order allow,deny
    Deny from all</files> 

DefaultType text/plain

HostnameLookups Off

ErrorLog /var/log/apache2/error.log

LogLevel warn

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

# Include all the user configurations:
Include /etc/apache2/httpd.conf

# Include ports listing
Include /etc/apache2/ports.conf

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined

Include /etc/apache2/conf.d/

Include /etc/apache2/sites-enabled/

#ServerName afewguyscoding.com
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8
PassengerDefaultUser www-data

I am fairly sure that my DNS is configured properly. Here are my zone files.

; afewguyscoding.com [73015]
$TTL 86400
@    IN  SOA ns1.linode.com. david\.stites.afewguyscoding.com. 2011062863 14400 14400 1209600 86400
@        NS  ns1.linode.com.
@        NS  ns2.linode.com.
@        NS  ns3.linode.com.
@        NS  ns4.linode.com.
@        NS  ns5.linode.com.
@            MX  10  ASPMX.L.GOOGLE.COM.
@            MX  20  ALT1.ASPMX.L.GOOGLE.COM.
@            MX  20  ALT2.ASPMX.L.GOOGLE.COM.
@            MX  30  ASPMX2.GOOGLEMAIL.COM.
@            MX  30  ASPMX3.GOOGLEMAIL.COM.
@            MX  30  ASPMX4.GOOGLEMAIL.COM.
@            MX  30  ASPMX5.GOOGLEMAIL.COM.
@            A   72.14.183.14
blog            A   72.14.183.14
clients            A   72.14.183.14
coupious            A   72.14.183.14
lbbs            A   72.14.183.14
staging            A   72.14.183.14
www            A   72.14.183.14
webmail            CNAME   ghs.google.com.

; davidheartsrachel.com [200479]
$TTL 86400
@    IN  SOA ns1.linode.com. david\.stites.afewguyscoding.com. 2011062862 14400 14400 1209600 86400
@        NS  ns1.linode.com.
@        NS  ns2.linode.com.
@        NS  ns3.linode.com.
@        NS  ns4.linode.com.
@        NS  ns5.linode.com.
@            MX  10  ASPMX.L.GOOGLE.COM.
@            MX  20  ALT1.ASPMX.L.GOOGLE.COM.
@            MX  20  ALT2.ASPMX.L.GOOGLE.COM.
@            MX  30  ASPMX2.GOOGLEMAIL.COM.
@            MX  30  ASPMX3.GOOGLEMAIL.COM.
@            MX  30  ASPMX4.GOOGLEMAIL.COM.
@            MX  30  ASPMX5.GOOGLEMAIL.COM.
@            A   72.14.183.14
blog            A   72.14.183.14
staging            A   72.14.183.14
www            A   72.14.183.14
webmail            CNAME   ghs.google.com.

One thing to note is that I have not tried using nginx instead of Apache to see if I get the same behavior.

2 Replies

<virtualhost *:80="">ServerAdmin [email protected] ServerName davidheartsrachel.com ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net</virtualhost>

I think this is your problem. You're using commas to separate sites in the ServerAlias directive, but you're supposed to use spaces.

Also, if it still doesn't work, try combining everything into a single ServerAlias directive rather than having two of them.

Erasmus.

You were right. Thank you x12390123809.

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