starbeamrainbowlabs
starbeamrainbowlabs

Reputation: 6106

Is there a reason why I should have a proxy in front of my Node.JS server?

Why should I proxy requests through to my Node.JS server using something like Nginx?

Why not allow access to the node server directly?

Upvotes: 0

Views: 74

Answers (2)

Calamar
Calamar

Reputation: 1627

I recommend you to read chapter 3 of "Deploying Node.js" by Sandro Pasquali (Packt Publishing) specially from page 69 onwards.

I will cite a couple relevant of paragraphs:

Using Nginx

According to http://www.linuxjournal.com/magazine/nginx-high-performance-web-server-and-reverse-proxy: "Nginx is able to serve more requests per second with less resources because of its architecture. It consists of a master process, which delegates work to one or more worker processes. Each worker handles multiple requests in an event-driven or asynchronous manner using special functionality from the Linux kernel (epoll/select/poll). This allows Nginx to handle a large number of concurrent requests quickly with very little overhead."

Load balancing with Node

File serving speeds are, of course, not the only reason you might use a proxy such as Nginx. It is often true that network topology characteristics make a reverse proxy the better choice, especially when the centralization of common services, such as compression, makes sense.

Upvotes: 0

alandarev
alandarev

Reputation: 8635

Internet is unfriendly and hard to survive place.

Having Nginx between your client and Node.js obviously allows you to use the advantages Nginx offers. So what are these?

  1. HTTPS can be set-up without touching any code in your Node application. It is tricky otherwise, and can compromise your HTTPS private key, if Node app can be exploited.
  2. Gzipping the communication can be done avoiding any changes in Node application.
  3. Authorization. For instance, Nginx can automatically block unwelcomed spiders.
  4. If you have more than one application, Nginx will serve as an independent router.
  5. And more...

Summing it up, Nginx will do the server stuff, so that developing your application, you do not need to worry about the administrative and common configuration aspects of a web server.

Upvotes: 1

Related Questions