June 2018
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

WordPress Quotes

Are you bored with life? Then throw yourself into some work you believe in with all your heart, live for it, die for it, and you will find happiness that you had thought could never be yours.
Dale Carnegie

Recent Comments

June 2018
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
252627282930  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (26)
Ansibile (17)
Apache (124)
Asterisk (2)
cassandra (2)
Centos (207)
Centos RHEL 7 (250)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (24)
Eassy (11)
EXCHANGE (3)
Fedora (6)
ftp (5)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (6)
JBOSS (32)
jenkins (1)
Kubernetes (1)
Ldap (4)
Linux (188)
Linux Commands (167)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (21)
MYSQL (80)
Nagios (5)
NaturalOil (13)
Nginx (27)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (33)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (11)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (59)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

16 visitors online now
5 guests, 11 bots, 0 members

Hit Counter provided by dental implants orange county

Reverse Proxy for Node.js application using Apache

Node.js

Node.js is widely used to build web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely. The best side is that we don’t need a host container for building a web app just means including a library that listens for HTTP requests on a port and responds. It is as simple as just coding your app and let it listen on any non-privileged port. Eg. 3000.

Need for configuring Apache with Node.js

With time things started getting complicated. The requirement of running node applications on privileged ports like 80, 443 starts emerging up.

Advantages of running Node.js with Apache

  1. It provides a cherry topping over cake, You can combine functionality from other languages like PHP with your node app
  2. Enhancing Security using Apache mod_proxy, nginx or haproxy to route requests to apps. This sit as a layer between your apps and the wide web.
  3. It Fulfills need to cache your static content and handle/scale to more users/connections per second than your node app probably can.
  4. It can also take care of the https termination, subdomain routing, redirects and things like that.
  5. Adds option to scale your application by performing load balancing leads to avoiding downtime for production environments.
  6. Allows the user to run multiple Node.js on HTTP port.
  7. This tutorial will guide you through to achieve these requirements.

Prerequisites:

LAMP Server with Node.js and npm installed over it. I am using Ubuntu machine for this demo

Using Apache’s Mod_Proxy Module (Non – SSL)

Enable the mod_proxy and mod_proxy_html Apache modules. They should be available by default so just enable them with the a2enmod command. sudo a2enmod proxy sudo a2enmod proxy_http. For more information on mod_proxysee the apache official documentation.
Condition: You must have started you node application and it is successfully over http://mydomian.com:3000/

<VirtualHost *:80>
  ServerName mydomain.com
  ServerAlias www.mydomain.com
  DocumentRoot /var/www/nodeapp/
  Options -Indexes
  ErrorDocument 503 /check.html

  ProxyRequests on
  ProxyPass /check.html !
  ProxyPass / http://mydomain.com:3000/
  ProxyPassReverse / http://mydomain.com:3000/
</VirtualHost>

We have created the virtual host for domain mydomain.com on which we want to run a node application. We have enabled the proxy module in apache and check.html will not be proxied through but will instead be served by the Apache server as a ‘normal’ page (the! means it won’t be sent through; for more info on the proxypass directive see the apache official documentation.

Using above proxy configuration in a vhost file you will magically get your node server’s responses running over http://localhost:3000/ by simply running the domain namemydomain.com.

Using Apache’s Mod_Proxy Module (SSL)

Condition: you must have started you node application and it is successfully over https://mydomian.com:3000/

<VirtualHost *:443>
  ServerName mydomain.com
  ServerAlias www.mydomain.com
  DocumentRoot /var/www/nodeapp/
  Options -Indexes
  ErrorDocument 503 /check.html

  SSLProxyEngine On
  ProxyPass /check.html !
  ProxyPass / https://mydomain.com:3000
  ProxyPassReverse / https://mydomain.com:3000
  ProxyPreserveHost On

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/mydomain.com.crt
  SSLCertificateKeyFile /etc/apache2/ssl/mydomain.com.key
  SSLCertificateChainFile /etc/apache2/ssl/mydomain.com:3000.ca-bundle
</VirtualHost>

Secondary Option:

Routing Application Using IPTABLES

One way is route traffic of port 80 to desired port internally using iptables. In below example, we have routed all incoming traffic on port 80 to port 3000.

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam