Skip to content

How to configure Reverse-Proxy Nodejs alongside Apache and Nginx

In this case we just having one static IP. We have an application, let’s say it personal website or blog which has pointed by domain name, for example : yourdomain.com.

Generally yourdomain.com defaultly use port 80 (http), so whoever users accessing your blog, they didn’t need to specifies the port. And then to we would showing a demonstration about nodejs application to the newbie user, let’s say here the user is they from non IT department. In order to make the url for the demonstration keep look pretty demonodejs.yourdomain.com without typing the port on the end section like demonodejs.yourdomain.com:2112, oh yeah it’s not good looking URL format for newbie :D. Of course, here we talk about users experiences.

As we know if the nodejs running on the port 80 is impossible because port 80 is already used by another app (let’s say here used by personal web app). So we need to run the nodejs app on another port in the machine.

And how to make it accessible as pretty as could? We can use Reverse-Proxy to do that.

reverse proxy

 

First, let’s create a nodejsĀ  app called index.js and bind it to a port besides port 80.

 

next steps, let’s point the nodejs app port above to port 80. At this moment I just explain reverse-proxy on Apache and Nginx.

For Apache,

Create a virtual host for the nodejs app. And make sure mod_proxy on the httpd configuration has been enabled.

$ sudo nano /etc/httpd/sites-available/nodejs.conf

Save and exit, then create link
$ sudo ln -s /etc/httpd/sites-available/nodejs.conf /etc/httpd/sites-enabled/nodejs.conf
then restart the apache service.
$ sudo apachectl restart

For Nginx,

let’s create a virtual host for the nodejs app inside configurations folder.

$ nano /etc/nginx/conf.d/nodeapp.yourdomaindotcom.conf

Save and exit, then restart Nginx service.

$ sudo service nginx restart

And on the final steps, let’s run the nodejs app,

$ node index.js

or if you are using forever

$ forever start index.js

app running on local domain

and then access demonodejs.yourdomain.cominspect request

On the figure above, I created a simple chat app using socket.io and we can see that the domain for demo node app still pointed to port 80.

Oke, finish ^_^

It's only fair to share...Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn1
Published inJavascriptNetworkingNodejsProgrammingTips and Trik

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


9 × = sixty three