Answer the question
In order to leave comments, you need to log in
How does a web server and node js work together? Why is Nginx needed?
Hey! I just started to dive into the world of the backend, and sometimes I don’t quite understand what is needed and why.
In general, I decided to make a simple bulletin board, I have two servers on Node.Js, one gives statics, the other - an api that generates requests to the database. But I recently learned about such a thing as Nginx (and, in general, about other web servers). And now I have a dilemma, I'm generally confused, and I don't understand what is right, and what is needed for what.
As I understand it, Nginx and Node Js can work together, but then who is responsible for what, if routing is done using React, Node gives all the necessary files, Node also makes requests, which then generally requires a web server on Nginx, And what task will he perform?
Why do you need Nginx, Apache, etc. at all? if the entire server part can be organized on node, or in any other language and framework?
Answer the question
In order to leave comments, you need to log in
The simplest - nginx gives statics. On large volumes, doing this through the Node is inefficient.
More complicated - nginx allows you to control the progress of the request. For example, redirect to https.
Even more difficult - you can configure nginx so that it intelligently balances requests between several backends and automatically blocks too frequent connection attempts.
Nginx is very good at doing a certain part of the work related to the http request on an industrial scale, so this part of the work is delegated to it.
I use nginx for the reason that several applications are running on the same server, with its help it is convenient to combine them all "under one roof", without renting a separate instance for each of them. In a situation with a shortage of IPv4 addresses, this is somehow wasteful, and so - each application listens to a separate port, nginx listens to 80 and 443 and proxies all requests by domain name to them.
And it’s much easier to transfer all the work of ensuring client communication with the server to nginx - you don’t need to separately do request logging in each application, work on obtaining and renewing SSL certificates, you can focus on solving a specific problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question