Apache config: Two different rails apps using same domain na


#1

The problem I’m solving here is that I have two different Rails
applicatons
that uses the same domain name. One handles the www (e.g.
www.mycoolapp.com)
and is used as the main site, and the other handles the user subdomains
(e.g… someuser.mycoolapp.com). The DNS stuff and the Apache virtual
hosts
were all set up, the two rails apps are in place in the file system, and
the
proper .fcgi replacements were made in the .htaccess files. The
following
are the configuration details that I applied to test this scenario:

File System:
Main application (www.mycoolapp.com) at /home/user/apps/mainsite
User application (someuser.mycoolapp.com) at
/home/user/apps/usersite

Apache Configuration:

NameVirtualHost *:80
…[other stuff here (e.g FastCgi directives, and etc.)]…
<VirtualHost *:80>
ServerName mycoolapp.com
ServerAlias .mycoolapp.com
DocumentRoot /home/user/apps/mainsite/public
RewriteEngine On
# If the host requested doesn’t begin with www (or no subdomain),
rewrite to usersite directory
RewriteCond %{HTTP_HOST} !^(www.)?mycoolapp.com? [NC]
RewriteRule ^(.
)$ /home/user/apps/usersite/public/$1

I could see the main site (www.mycoolapp.com) – it loads up fine. For
the
user site, the rails application error page is displayed, and the
following
entry in my apache error log:

mod_rewrite: maximum number of internal redirects reached. Assuming
configuration error. User ‘RewriteOptions MaxRedirects’ to increase the
limit if necessary.

My erroneous rewrite statements above is the problem. Anyone has ideas
out
there? Thanks.


#2

I think I’ve solved this problem by skipping the rewrite stuff
altogether:
Looking at the following Apache config:

Main site vhost

<VirtualHost *:80>
ServerName mycoolapp.com
ServerAlias www.mycoolapp.com
DocumentRoot /home/user/apps/mainsite/public

User site vhost

<VirtualHost *:80>
ServerName user.mycoolapp.com
ServerAlias *.mycoolapp.com
DocumentRoot /home/user/apps/usersite/public

This split vhost configuration works. Requests to www.mycoolapp.com and
mycoolapp.com are handled by the first one (main site), while all others
go
to the user site. The subdomain “user” is chosen arbirtarily, but the
important part is the ServerAlias that has the subdomain wildcard.

Also, along the way in your Rails application, some subdomains should be
reserved and be prevented from being created as usernames. Names like
www,
ftp, admin, test, tmp, billing, and many others should not be used as
username and hence become subdomains of your site. They can be blocked
at
the data layer, controller, and even in the Apache configuration.

“Jake P.” removed_email_address@domain.invalid wrote in
message news:e4fprb$e1e$removed_email_address@domain.invalid…