I will focus on this answer in your second question, since the first (Node replaces NGINX?) falls into a more opinionated field.
About the Node.js + NGINX architecture
The approach of deploying a network server in front of other servers can bring some advantages in terms of both security and performance, depending on your system architecture.
The concept is relatively simple: add a server that is responsible for receiving and forwarding incoming requests from outside (this server is usually called reverse proxy), and it is the task of this reverse proxy to pass on these requests internally to the other servers to process the related tasks.
This means that the servers that actually run the tasks are never directly exposed to the external network. Every request that comes to them before had to go through the reverse proxy. But what are the advantages of this?
Security
Mature and "hardened" servers during years of real-world testing such as NGINX have numerous built-in features that make it easy to protect your server from possible external attacks using few configuration lines (modules http_limit_request
, http_limit_conn
and client_header_timeout
are some examples of this).
In addition, adding a server focused exclusively to deal with requests performatively ahead of your other servers, allows you to have a possible increase in stability and security right away, since a server like NGINX was built exclusively for 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 to accomplish all the tasks in building a home, a specific single server (or language) may also not be the best solution for all parts of your system. With a reverse proxy it is much easier to receive requests and forward them according to the requested task.
This allows you to achieve greater modularity in your application, so that each server has a specific focus, example:
- Module in C: Responsible for processing tasks where performance is crucial,
- Module in PHP: Rest of the application, where productivity is more important than performance
If your application was divided into the above modules, using a reverse proxy that redirects requests to their respective modules would leave the scope very well separated and organized.
Performance
As said before, servers like NGINX were 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 with an approach Event Driven similar to Node.js), and it is no wonder that he performs this role extremely well. This also means that sometimes it can be much more advantageous to use a server like these to serve as an input port to your system, than another newer solution with a very comprehensive focus (as is the case with Node.js). Here we come back to the question of scope: each tool has a focus, and since NGINX’s focus is on performance in the processing of requests, it is no wonder that it serves this purpose better than other solutions without the same focus.
Other answers with more detail about the advantages of using a reverse proxy ahead of Node.js can be found here:
https://stackoverflow.com/questions/16770673
https://stackoverflow.com/questions/9967887
It’s like the chat I’ve heard for about 10 years that the web was going to replace the desktop. I said it was nonsense, I see today that it is really bullshit (not that people are not trying insistently, the fact is that the result is always very bad no matter how much they insist). What you said is one more of these fashions, because everything that Ode has, any serious language had in the past. What is new to kids of the web on Node, for example it does not impress much who was already programming for a while. NOTE: It is not a criticism of the product, but the thought that everyone has to change "fashion".
– Bacco
Yeah. I’m a back-end developer. I’m replacing apache with Nginx due to some benchmarking results. But I’m still in php. I’m trying to find a reason to replace my old architecture with Nodejs. And I don’t think so.I agree 100%. I don’t run behind fashion. But I wonder if there’s something I’m not seeing.
– zwitterion
Exactly, and if you move, what is Node.js for? Why not C# or many others? I’m not saying that this is better than that, nor the other way around. I just want to say that there is and there was a lot on the market before Node.js, and it will continue to be. I remembered the furore of Ruby on Rails, the guys said they were going to end the other Web technologies, and today I hardly see.
– Bacco
@zwitterion In terms of performance, other languages (Go, Java, C#, Javascript/Node.js) generally bring more satisfactory results and greater scalability. If I were to choose today, I would focus on Go which, in addition to bringing a better performance than both Node.js and PHP, still has a ridiculously low memory consumption (and a more productive syntax than a C or C++, for example).
– Kazzkiq
@Kazzkiq Precisely, there are a thousand different reasons for each to choose another option. I use PHP for a lot of things, even though PHP is an extremely bad thing. For things I need more performance and stability, I use another language on the same server (which is none of the above) and would not go to Node.js, which was born more limited than what I use today. So, it is not possible to define what the path is, each one has to put all the weights in the balance according to their reality. I believe that despite an interesting discussion, pro formato do site I find complicated the question.
– Bacco
@Bacco, I’ve updated my question.
– zwitterion
@zwitterion had even edited the previous comment on this. I find it an interesting discussion, but I think that the Q&A format does not work well. If you catch a busy day in the network chat you can go far with the subject (I think it became too wide and runs the risk of turning opinionated debate, to speak the truth).
– Bacco
@Kazzkiq, I thought about it. Memory these days, it’s not so scary. 2Semin ago I was doing a job on a computer with 128G of memory RAM and 31 processors. This is something tangible to acceptable nowadays. When performing, you’ve seen the benchmarking of php7? hega to be up to 40%-50% better than traditional languages. http://www.zend.com/en/resources/php7_infographic
– zwitterion
@Bacco this debate should be held where? Tbm I think it can be barred, but it’s a topic that shouldn’t be outside a community of programmers. After all, we are all living in moments of doubt and running in fashion is the worst thing there is. We have to have solid gasps to decide one architeur and exclude another.
– zwitterion
@zwitterion this comparison of the guys was made only with scripting language. Not that I think "unfair", pq PHP is basically a scripting language, that people invented to use in other ways, but if you put any compiled language (or even other based on intermediate Runtime) close, the graph becomes much less attractive pro PHP.
– Bacco
Thanks for the link. I will be aware of everything that this company says. I don’t think I have ever seen anything so serious to talk such nonsense together. All silly assumptions to sell a product. It’s not just biased information, it’s the ingenuity of the author. He understands nothing of the subject and believes in Sací Pererê. Node brings zero innovation. And what they did around the Node, not the Node itself, that worked, is not only copyable for other technologies, but has already been copied, as well as everything, including Node does. I took the illustration, since there is explicitly prohibiting the use.
– Maniero
Ok @bigown, I hadn’t even noticed the photo ban. So your comment seems to be in tune with my print. It does seem to be a fad - more of the same at the end of the day.
– zwitterion