简体   繁体   English

在Node.js服务器中支持HTTPS或要求反向代理进行HTTPS

[英]Support HTTPS in Node.js server or require reverse proxy for HTTPS

I'm writing an open-source Node.js application that implements a HTTP server for API calls. 我正在编写一个开源的Node.js应用程序,该应用程序实现了用于API调用的HTTP服务器。 Supporting HTTPS in Node.js isn't hard, but it adds a little complexity and cases you need to thing about: 在Node.js中支持HTTPS并不困难,但是会增加一些复杂性和您需要考虑的情况:

  • Path to key and cert should be configurable => More settings / documentation 密钥和证书的路径应该是可配置的=>更多设置/文档
  • App should handle errors when key and cert is missing or path is wrong => More code and test 当密钥和证书丢失或路径错误时,应用程序应处理错误=>更多代码和测试
  • Docker image must pass an external key and cert to the application running in the container => More code and documentation Docker映像必须将外部密钥和证书传递给在容器中运行的应用程序=>更多代码和文档

It feels a bit like reinventing the wheel. 感觉有点像重新发明轮子。 I'm personally using a reverse proxy that handles the HTTPS part of all my sites. 我个人使用的是处理我所有站点的HTTPS部分的反向代理。 The servers in the background are all just HTTP. 后台的服务器都是HTTP。

Is it ok to require a reverse proxy or is it better to support HTTPS directly as most users aren't using a reverse proxy? 是否可以要求使用反向代理,还是因为大多数用户不使用反向代理而直接支持HTTPS更好? What's the common server setup and recommend way when writing an open-source Node.js application? 编写开源Node.js应用程序时,常见的服务器设置和推荐方式是什么? How to make it as easy as possible for most users to use my app? 如何使大多数用户尽可能轻松地使用我的应用程序?

Reverse proxy is preferable for most of the scenarios since we can make use of security, load balancing, cache control, etc. kind of things. 在大多数情况下,反向代理是可取的,因为我们可以利用安全性,负载平衡,缓存控制等功能。 Also we can use for logging purpose so that we can maintain a security layer on all the server activities and data behind this proxy. 此外,我们可以将其用于日志记录目的,以便我们可以在此代理后面的所有服务器活动和数据上维护安全层。 As you mentioned, there will have some more lines of code to write but the system will persist more powerful. 如您所提到的,将有更多的代码行需要编写,但是系统将保持更强大的功能。 I recommend to have a reverse proxy to make the things more robust and secure. 我建议使用反向代理,以使事情变得更健壮和安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM