Joyent

Translations of this page:

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:

  1. Your Joyent domain is: sample.fb.joyent.us
  2. The subdomain of the new virtual server will be: app2.sample.fb.joyent.us
  3. The default Mongrel instance is running on port 8001
  4. The new Mongrel instance will run on port 8002

Creating the virtual server

  1. Login to Virtualmin
  2. Click Create Virtual Server
  3. Domain name: app2.sample.fb.joyent.us
  4. Choose a password
  5. Click Create Server

Log in to your virtual server

Use an SSH program such asPutty to login to your server:

  1. Host Name: IP address of your account
  2. Port: 22
  3. Protocol: SSH
  4. Click Connect
  5. Login as: app2.sample.fb.joyent.us
  6. Enter the password you assigned to your virtual server (above)

Create a Rails application

  1. cd web/public
  2. rails app2

Create a boot action

  1. Login to Virtualmin
  2. Click Services
  3. Click Bootup Actions
  4. Click Add Mongrel
  5. Action name: app2
  6. Port number: 8002
  7. Rails root directory: /home/sample/web/public/app2
  8. 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:

  1. Login via SSH (see above)
  2. cd web/public
  3. touch .htaccess
  4. chmod 664 .htaccess
  5. vi .htaccess
  6. 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:

  1. Login to Virtualmin
  2. Click Server Configuration
  3. Click Edit Proxy Website
  4. Select No for Proxying enabled?
  5. 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.

 
facebook/kb/virtualserver.txt · Last modified: 2008/07/01 17:42 by lderezinski
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki