June 2019
« May    


WordPress Quotes

Happiness depends more on the inward disposition of mind than on outward circumstances.
Benjamin Franklin
June 2019
« May    

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (36)
Ansibile (19)
Apache (134)
Asterisk (2)
cassandra (2)
Centos (211)
Centos RHEL 7 (267)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (30)
Eassy (11)
ELKS (1)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
health (1)
horoscope (23)
Hyper-V (10)
IIS (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (6)
Ldap (5)
Linux (188)
Linux Commands (166)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (35)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (35)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
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 (62)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)

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

Who's Online

16 visitors online now
4 guests, 12 bots, 0 members

Hit Counter provided by dental implants orange county

Reverse Proxy for Node.js application using Apache


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.


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/

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

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


Protected by WP Anti Spam