Browse files

Production hosting support, also easy install of Node and MongoDB on …

…Ubuntu

* Production hosting is now supported. Create a data/hosts file for the site and list as many hostnames as you want. The proxy will map those hostnames to that site. Boom!
* install-node-and-mongo-on-ubuntu.bash installs Node and MongoDB on Ubuntu according to best practices. See the script for more information.
  • Loading branch information...
1 parent 39c99bf commit 48d97c209696cacc780f9b690571a7cbd94fd1de @boutell boutell committed Apr 27, 2012
Showing with 29 additions and 5 deletions.
  1. +13 −0 README.md
  2. +10 −2 sc-proxy/install-node-and-mongo-on-ubuntu.bash
  3. +6 −3 sc-proxy/server.js
View
13 README.md
@@ -67,6 +67,19 @@ Tip: you should definitely set up a trusted ssh public key that allows you to ss
In the `example` folder you'll find an example of ndoe app deployment, with all the important bits already set up (be sure to look in `example/deployment`). The `start` script integrates with `sc-proxy` by registering a port number for the project to listen on via the data/port file, and the provided example node app consults that file as well at startup.
+Production Hosting
+==================
+
+You can do production hosting with `sc-proxy` as well.
+
+Just create a `data/hosts` file for each site. In that site, list the hostnames that the site should respond for, like this:
+
+ myexample.com
+ www.myexample.com
+ some-alternate-name.com
+
+Note that if `data/hosts` exists, `sc-proxy` will stop responding on the staging subdomain for that site. Which doesn't bother you, because you have separate staging and production servers... I hope!
+
Warnings and Limitations
========================
View
12 sc-proxy/install-node-and-mongo-on-ubuntu.bash
@@ -3,15 +3,22 @@
# Install the latest official stable versions of Node and MongoDB from
# their own repositories, not the older stuff in the Ubuntu repositories.
+# Also installs the requirements for building node extensions (i.e. gcc).
+
+# Finally installs the 'forever' npm package globally, because
+# our recommended start and stop scripts rely on it.
+
# Configures MongoDB to accept connections on localhost only - a safe default
# configuration. If you don't like this, you should explicitly configure MongoDB
# to allow connections from some safe set of IPs or to require authentication.
# MongoDB's default configuration is insecure.
-# Assumes you have at least Ubuntu 10.04 (I haven't tested further back)
+# Assumes you have at least Ubuntu 10.04 (I haven't tested further back).
+echo "Installing requirements for building node extensions" &&
+apt-get -y install build-essential &&
echo "Installing Node" &&
-apt-get install python-software-properties &&
+apt-get -y install python-software-properties &&
add-apt-repository ppa:chris-lea/node.js &&
apt-get -y update &&
apt-get -y install nodejs npm &&
@@ -25,4 +32,5 @@ echo "Installed MongoDB" &&
echo "Configuring MongoDB to listen only on localhost" &&
echo "bind_ip = 127.0.0.1" >> /etc/mongodb.conf &&
/usr/sbin/service mongodb restart &&
+npm install -g forever &&
echo "Success!"
View
9 sc-proxy/server.js
@@ -20,8 +20,6 @@ fs.watch(config.appsDir, { persistent: true }, resetRouter);
// whether the performance of using fs.watch for these would be acceptable
setInterval(resetRouter, 60000);
-console.log(options);
-
var proxyServer = httpProxy.createServer(options).listen(config.port, config.bindIp);
// Reset the routes on the fly
@@ -68,6 +66,11 @@ function rebuildRouter(failQuickly)
{
hosts = fs.readFileSync(hostsPath, 'UTF-8').replace(/\s+$/, '');
hosts = hosts.split(/\s+/);
+ // Don't get confused by an empty file returning one string on split
+ if ((hosts.length === 1) && hosts[0] === '')
+ {
+ hosts = [];
+ }
}
port = fs.readFileSync(config.appsDir + '/' + site + '/data/port', 'UTF-8').replace(/\s+$/, '');
if (port < 1000)
@@ -90,7 +93,7 @@ function rebuildRouter(failQuickly)
}
hosts.forEach(function(host) {
router[host] = local;
- }
+ });
}
return router;
}

0 comments on commit 48d97c2

Please sign in to comment.