Why you should use Nginx to Deploy Node Application Servers

Prasad Beligalage
4 min readOct 26, 2022

--

The HTTP module of Node.js is an excellent tool you can use to create Web Application Servers. Although the Node application server itself can work alone to respond to client requests let’s see why it’s recommended to deploy a Node application server with Nginx.

There are several ways that you can deploy a Node web application server.

  • Using a dedicated Node.js hosting platform

A dedicated Node.js hosting platform, generally known as SaaS (Software as a Service) or PaaS (Platform as a Service) are the popular and widely used methods to deploy Node applications. Using such a platform is pretty much simple and straightforward. Heroku is a great example for such a platform that is based on PaaS. Nevertheless, SaaS or PaaS may introduce some downsides too. One major weakness of PaaS is, you wouldn’t get full control over the services or the server. Another common issue is the performance as these types of platforms (SaaS or PaaS) usually have a slow performance compared to the other methods.

  • Direct access

The application you create using Node’s HTTP module on the Node platform is a Web Application Server. A Web Application Server is composed of a HTTP server, a web content delivery service and application logic component. Therefore, a Node Web Application Server has the ability to successfully respond to client requests on its own.

In order to access the Node app directly, all you have to do is to run the Node application and point the DNS “A” record to your server’s IP address. Once you’ve done that, your application should be up and running.

However, unlike using a complete web server such as Apache or Nginx, this method has some limitations. One disadvantage of this method is that you cannot deploy more than one server at a time. Which means, your entire server machine is going to be occupied by only one web application. Apart from that, a security concern of this method is, if anyone has found your server’s IP address, then they can point any domain name to your IP address (unless you explicitly check the incoming domain name in your application).

However, because of these drawbacks, it is not recommended to use direct access methods for production level applications.

In order to overcome the limitations that we’ve just described, we can use the reverse proxy feature of Apache or Nginx, where it can be placed as an intermediate between the client and the Node app.

In this short article, we will see why it’s beneficial to use Nginx as your reverse proxy.

How Nginx works

As can be seen in the diagram, basically Nginx has a HTTP server and a “Static Content Serving” component to serve the static web content. The HTTP server component itself can only handle HTTP requests received from the client, but it can’t respond to the client with content. However, a HTTP server can forward the request to another application server for further processing and to respond back to the client. With normal Nginx configuration, the HTTP server handles the client’s http requests and the static content serving component serves the static content to the client.

How to use Nginx as a Reverse Proxy

You have seen that Nginx is composed of two components. In order to make Nginx a reverse proxy, we are going to use just only the HTTP server component. This is because the, critical content serving functionality is going to be managed by our Node Application (also known as the Node Web Application server). Thus, with reverse proxy configuration, Nginx stays as an intermediate person who forwards the client requests to the Application Server (Node app) and responds back to the client with the Node server’s responses.

(This article explains how to deploy a Node web Application server with Nginx Reverse Proxy on Ubuntu 22.04)

Why Nginx as the Reverse Proxy?

Nginx has been particularly developed as a solution to the performance issues that the other web servers had, thus Nginx is one of the fastest web servers existing today. Not only does Nginx perform faster, but also it has less memory consumption than other web servers such as Apache.

Another great benefit is that, Nginx Reverse Proxy feature, will let you host more than one app (Node, PHP, python, WordPress Joomla etc.) at the same time on a single server.

Apart from faster performance and Reverse Proxy feature, you can also get the benefits of extra security, Streaming, SSL/TLS termination, web acceleration, caching and load balancing functionalities provided by Nginx.

Conclusion:

This article briefly explained what Node deployment is, and how Nginx can be beneficial for Node deployment. So, now it’s your time to try it out and see the benefits of Nginx Reverse Proxy.

--

--