Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Configure Node Server

Michael Kohler edited this page Apr 29, 2015 · 5 revisions

Configure Node Server

In NodeJS, there is not much configuring to running node. But node is not efficient in handling many duties of a complete web server. So by default, we do not want to run node in PORTs lesser then 1024. We use either Apache or Nginx to handle those functions for node. I prefer Nginx due to it's efficient web serving capabilities.

Thus here we will run node in PORT 8080 and we will configure Nginx to bypass PORT 80 to PORT 8080 with CNAME given under parked domain.

Note : <domain_name> is to be replaced with your own domain name. Eg: mozillakerala_org

Following is the nginx setup for your domain / subdomain

# mkdir -p /srv/www/<domain_name>/subdomains/mko/

# mkdir -p /srv/nginx/

# chmod -R 755 /srv/

# chown -R user:nginx /srv/www/

# vim /srv/nginx/mko_<domain_name>.conf

Following should be the content of file opened by above command

server {
    listen 80;
    server_name dev.<domain_name>;
    include /etc/nginx/default.d/*.conf;
    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    location /assets {
        root   /srv/www/<domain_name>/subdomains/mko/;
    }
    location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }
}

Before we restart nginx, we need to test the server for configuration errors. Use following command to test nginx configuraiton,

# nginx -t

To restart nginx use following command

# service nginx restart