What is the benefit of using NginX for Node.js?

前端 未结 3 1447
生来不讨喜
生来不讨喜 2021-02-05 03:16

From what I understand Node.js doesnt need NginX to work as a http server (or a websockets server or any server for that matter), but I keep reading about how to use NginX inste

相关标签:
3条回答
  • 2021-02-05 03:38

    In addition to the previous answers, there’s another practical reason to use nginx in front of Node.js, and that’s simply because you might want to run more than one Node app on your server.

    If a Node app is listening on port 80, you are limited to that one app. If nginx is listening on port 80 it can proxy the requests to multiple Node apps running on other ports.

    It’s also convenient to delegate TLS/SSL/HTTPS to Nginx. Doing TLS directly in Node is possible, but it’s extra work and error-prone. With Nginx (or another proxy) in front of your app, you don’t have to worry about it and there are tools to help you securely configure it.

    0 讨论(0)
  • 2021-02-05 03:44

    But be prepared: nginx don't support http 1.1 while talking to backend so features like keep-alive or websockets won't work if you put node behind the nginx.

    UPD: see nginx 1.2.0 - socket.io - HTTP/1.1 - Proxy websocket connections for more up-to-date info.

    0 讨论(0)
  • 2021-02-05 03:54

    Here http://developer.yahoo.com/yui/theater/video.php?v=dahl-node Node.js author says that Node.js is still in development and so there may be security issues that NginX simply hides.
    On the other hand, in case of a heavy traffic NginX will be able to split the job between many Node.js running servers.

    0 讨论(0)
提交回复
热议问题