Setting up a basic HTTP server using Node on Mediatemple DV4
The previous tutorial I went through the process of setting up Node.JS on a Mediatemple DV4 hosting solution running CentOS 5 and Plesk 12.
In this tutorial I'm going to go through the steps to get a simple Express JS app running and to serve the content up on port 80.
Now since Apache uses port 80 we'll need to setup a proxy to allow traffic from the Node JS app to be served up on port 80.
This tutorial assumes you have a domain or sub-domain setup already or that you know how to do this.
The first thing we'll need to do is SSH into the server which is explained in the first tutorial.
Next you need to change directory to:
Where "your-domain-name-here" is the domain you're going to run your app on. If you're using a sub-domain, this will require an extra layer of travesal for example:
Next we'll need to run a couple commands to get Express JS installed, now this is your preference. I'm just using Express JS here to illustrate how to get a Node.JS HTTP server displaying on a system running Apache.
Run this command to install Express globally
npm install express -g
Next run this command to install the express generator
npm install express-generator -g
Once you've done this you'll be able to install a basic Express JS application.
To do that run the following command in the folder we want our app to run from.
You'll notice some text appear on the screen, now before you can actually run the app you need to install its dependencies by running the following command:
Node package manage will download all the dependencies outlined in the package.json file.
After this you're ready to start the application. Before doing do though we need to setup the proxy.
Theres acouple ways you can do this and for simplism lets use Plesk for this. Login to your Plesk administration panel and navigate to the domain and click on the following button shown in the image below:
The next thing we'll need to do is setup a Proxy pass in the "Additional directives for HTTP" input text area which is displayed in the image below:
Now you'll need to copy the following text into the box:
<Location /> ProxyPass http://localhost:3000/ ProxyPassReverse http://localhost:3000/ </Location>
Your Apache server exists on the local machine hence the proxy setup to reflect localhost and by default Express JS serves content up on Port 3000. So what's happening here is that all content served on port 3000 will appear at the default web port which is port 80.
Remember to click the OK button to save your changes.
Now back in the terminal, lets run one more command to start the Express JS application.
With that done, you should now be able to view the basic Express JS app in your browser by visiting the domain address that you selected.
Next tutorial I'll show you how to setup the Node app server to run forever.