Make Amazon EC2’s Port 80 talk to node.js

Nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.

Using nginx in front of node.js for extra security and usability.

Install nginx:

sudo yum install nginx

Modify /etc/nginx/nginx.conf to forward the “80” request to node.js server port “8888”

    server {
        listen       80;
        server_name  localhost;
        root         /usr/share/nginx/html;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        location / {
proxy_pass http://127.0.0.1:8888/;
        }

then restart nginx:

sudo /etc/init.d/nginx restart

Setup Node.js server on Amazon EC2

Three useful links:

http://www.bennadel.com/blog/2321-how-i-got-node-js-running-on-a-linux-micro-instance-using-amazon-ec2.htm

http://techprd.com/setup-node-js-web-server-on-amazon-ec2/

https://github.com/joyent/node/wiki/Installation

Here is what I did after logon to my first EC2 instance:

sudo yum update
sudo yum install gcc-c++ make
sudo yum install openssl-devel

wget http://nodejs.org/dist/node-latest.tar.gz
tar xzf node-latest.tar.gz
cd node-v0.10.30
./configure && make && sudo make install

To verify the setup, I created the following server.js:

var http = require("http");
http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);

After executed:

node server.js

The link http://localhost:8888/ should display a web page that says “Hello World”.

Steps to install npm:

sudo su
nano /etc/sudoers

Once inside the Nano editor, scroll to where you see the line:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Append the following value, “:/usr/local/bin”, to the end of that line. Save the file and exit the Nano editor.

git clone https://github.com/isaacs/npm.git
cd npm
sudo make install