Using Virtual Servers to Host Multiple Applications
Summary
If you would like to run multiple applications from your domain, virtual servers can be created to host each application.
For these instructions, we'll assume:
- Your Joyent domain is:
sample.fb.joyent.us - The subdomain of the new virtual server will be:
app2.sample.fb.joyent.us - The default Mongrel instance is running on port 8001
- The new Mongrel instance will run on port 8002
Creating the virtual server
- Login to Virtualmin
- Click Create Virtual Server
- Domain name:
app2.sample.fb.joyent.us - Choose a password
- Click Create Server
Log in to your virtual server
Use an SSH program such asPutty to login to your server:
- Host Name: IP address of your account
- Port: 22
- Protocol: SSH
- Click Connect
- Login as:
app2.sample.fb.joyent.us - Enter the password you assigned to your virtual server (above)
Create a Rails application
cd web/publicrails app2
Create a boot action
- Login to Virtualmin
- Click
Services - Click
Bootup Actions - Click
Add Mongrel - Action name:
app2 - Port number:
8002 - Rails root directory:
/home/sample/web/public/app2 - Click
Create
Proxy configuration
Unfortunately, the Virtualmin UI is set up to allow only one proxy. You'll need to disable that if you have turned it on. But first, we need to create a .htaccess file:
- Login via SSH (see above)
cd web/publictouch .htaccesschmod 664 .htaccessvi .htaccess- Use the following configuration:
# Joyent Inc.
# Proxy with .htaccess
# Revision 1.1, 2007/08/30
# This file is intended to go into the document root of your domain
# (typically web/public of your virtual server)
#
# A. Prelude
# A.1 Turn rewriting engine on
RewriteEngine on
#
# B. Catch all requests that are NOT to be proxied
# B.1 Apache does a better job with static files, so let's not proxy these
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
# B.2 Do not proxy the 'blog' subdomain (uncomment to enable)
# To define more, separate with a pipe character, e.g. 'blog|wiki'
# RewriteCond %{HTTP_HOST} ^(blog)\. [OR]
# B.3 Do not proxy the '/blog' path (uncomment to enable)
# To define more, separate with a pipe character, e.g. 'blog|forum'
# RewriteCond %{REQUEST_URI} ^/(blog) [OR]
# B.8 Do not proxy the default DAV, FCGI, and SVN paths
# To define more, separate with a pipe character (leave this condition the last one)
RewriteCond %{REQUEST_URI} ^/(dav|fcgi-bin|svn)
# B.9 Finally take all the exceptions above and make them just pass through (do not proxy)
RewriteRule ^(.+) - [PT,L]
#
# C. All other requests WILL be proxied
# C.1 Only the 'shop' subdomain should be proxied (uncomment to enable)
# To define more, separate with a pipe character, e.g. 'shop|store'
# RewriteCond %{HTTP_HOST} ^(shop)\.
# C.9 Warp speed to the proxy!
RewriteRule ^.*?app2/(.*)$ http://127.0.0.1:8002/$1 [P,QSA,L]
RewriteRule ^(.*)$ http://127.0.0.1:8001/$1 [P,QSA,L]
Now that our .htaccess file is in place, we can disable the default proxy if necessary:
- Login to Virtualmin
- Click
Server Configuration - Click
Edit Proxy Website - Select
NoforProxying enabled? - Click
Save and Apply
Viewing your new application
Problems configuring rails base URL
Although the above configuration allows you to create multiple rails applications on one Joyent account, you may run into trouble when trying to use your rails application: It appears that, by default, any links within the application will assume the app is in the root directory of the webserver, which it is not. If anyone knows how to fix this issue, please edit this wiki document and provide the details.