...as a reverse proxy to boost the performance.

Howto install Nginx in front of Node.js

Install Nginx on your Mac OS X

First install Nginx software:

$ brew install nginx

Edit Nginx config file

$ sudo emacs /usr/local/etc/nginx/nginx.conf

Example file:

worker_processes  1;
error_log  /var/log/nginx/error.log;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile        on;
    keepalive_timeout  65;

    # Gzip Compression
    gzip on;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_min_length  1000;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;

    proxy_cache_path  /tmp/nginx/cache  levels=1:2    keys_zone=STATIC:10m
                                         inactive=24h  max_size=1g;

    # This is your Node.js service you are hiding behind Nginx.
    # Edit name, ip and port to the correct one.
    # In this example my service is called simple-blog and running on ip 127.0.0.1 and port 8080.
    upstream simple-blog {
        server 127.0.0.1:8080;
    }

    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass      http://simple-blog;
            proxy_set_header       Host $host;
            proxy_cache            STATIC;
            proxy_cache_valid      200  1d;
            proxy_cache_use_stale  error timeout invalid_header updating
                                   http_500 http_502 http_503 http_504;
        }

        location /html {
            root   html;
            index  index.html index.htm;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Start the Nginx server:

$ sudo nginx

Check if the server is running:

$ wget -s http://localhost/

Stop the Nginx server:

$ sudo nginx -s stop

Reload the Nginx config file:

$ sudo nginx -s reload