I'm going to focus this answer on your second question, since the first Node replaces NGINX? ) falls into a more opinionated field.
About the architecture Node.js + NGINX
The approach of deploying a network server in front of other servers can bring some advantages both in terms of security and performance depending on the architecture of your system.
The concept is relatively simple: you add a server that is responsible for receiving and forwarding the incoming requests from outside (this server is usually called a reverse proxy ), reverse these requests internally for the other servers to process the related tasks.
This means that servers that actually run tasks are never directly exposed to the external network. Every request that arrives at them before had to go through the reverse proxy. But what are the advantages of this?
Security
Mature and "caged" servers over years of real-world testing such as NGINX have numerous built-in features that make it easy to protect your server against possible external attacks using a few configuration lines (the http_limit_request
, http_limit_conn
and client_header_timeout
are some examples of this).
In addition, by adding a server that is exclusively focused on dealing with requests on a performative basis in front of your other servers, you have a possible stability and security increase right away, since a server like NGINX was built exclusively with this purpose in mind (unlike Node.js for example, which has an infinitely more comprehensive focus and often may not have been optimized especially for this specific task).
Scope separation
Just as a hammer does not serve all the tasks in building a home, a single server (or language) may not be the best solution for all parts of your system. With a reverse proxy it is much easier to receive the requests and pass them on according to the requested task.
This allows you to achieve greater modularity in your application, so that each server has a specific focus, eg:
-
C module : Responsible for processing tasks where performance is crucial,
-
Module in PHP : Remaining application where productivity is more important than performance
If your application was split into the modules above, using a reverse proxy that redirects the requests to their respective modules would make the scope very well separated and organized.
Performance
As said before, servers like NGINX have been built from the first line of code with performance and scalability in mind. This type of server is focused exclusively on processing network requests (including an Event Driven similar to Node.js), and it's no wonder they play that role extremely well. This also means that sometimes it can be much more advantageous to use a server like these to serve as a gateway to your system than a newer, more comprehensive solution (such as Node.js) . Here we come back to the question of scope: each tool has a focus, and since NGINX's focus is on processing requests, it is no wonder that it serves this purpose better than other solutions without the same focus. >
Further answers in greater detail about the advantages of using a reverse proxy in front of Node.js can be found here:
link
link