Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

node.js - nginx reverse proxy or nodejs fetch?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Reasons to use the generic reverse proxy:

  1. You have a lot of different requests you need this for so it's simpler to have just one proxy that handles everything.
  2. Using nginx removes all work in processing the proxied requests to a separate process so it doesn't cause any load on your nodejs server.
  3. nginx "might" be more scalable than your own code in nodejs just because nginx is pretty highly optimized for these kinds of things. But, if this was a meaningful driver for your decision, you would have to measure to see if this was really the case or not (impossible to predict for sure without measuring).

Reasons to have your nodejs server do the work:

  1. You can do application-specific authentication before allowing a proxy request to be used.
  2. You can design application-specific requests that have your client specify only what you want to specify and your nodejs server can then translate that to the 3rd party website request, filling some parts with defaults, etc...
  3. You can trim the proxy response to just the data your client needs, speeding up client responses and trimming server bandwidth costs.
  4. You can combine multiple requests to the target into a single request/response between client and your nodejs server, allowing you to create more efficient requests, particularly on mobile or slow links.

Which is better depends entirely upon the specific requests and what exactly you're optimizing for. We can't name one as better than the other as they each have advantages and disadvantages so it ultimately comes down to which advantages and disadvantages matter more to you in your system.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...