gpt4 book ai didi

node.js - https如何与http通信

转载 作者:太空宇宙 更新时间:2023-11-03 15:10:08 25 4
gpt4 key购买 nike

我是 Google 云平台的新手。我在用 http 握手 https 时遇到问题,我看到一些文章中提到 HTTPS 不能与 HTTP 握手。

我正在描述我的方法。我有 2 个 Windows Server 2016 VM 实例。

  1. 第一个实例将是 React Server。 Instance External IP绑定(bind)了域名,也通过nginx反向代理实现了ssl证书。使用 443 并在 nginx.conf 文件中添加证书。假设其外部静态 IP 为:35.35.35.36
  2. 第二个实例将是 Node 服务器。现在,对于每个 API 请求,React Server 都会调用带有端口的 Node 服务器外部 ip。

假设此实异常(exception)部 IP 为:35.36.36.36。

现在对于每个调用 react 调用 api 即 http://35.36.36.36:3000/这将产生错误

your page was loaded over HTTPS, but requested an insecure resource

较早的情况,当前端在 http 上时,一切都很好。

我是否也应该为我的后端使用新的 ssl 证书。

Any help is really appreciated.

最佳答案

是的,您不能从 HTTPS 连接到 HTTP,前者是安全的,后者是不安全的:https://stackoverflow.com/a/37068063/2873331

这是创建 HTTPS 的唯一动机:

The principal motivation for HTTPS is authentication of the accessed website and protection of the privacy and integrity of the exchanged data while in transit. In HTTPS, the communication protocol is encrypted using Transport Layer Security (TLS), or formerly, its predecessor, Secure Sockets Layer (SSL).

HTTPS 请求与“代码”一起发送,只有正确配置的 HTTPS 服务器才能破译该代码。即使发件人和收件人之间的任何人都可以打开请求,他们仍然无法理解。只有知道“代码”的发件人和收件人才能破译消息。

因此,要么将 React 服务器转换为 HTTP 服务器(不推荐这样做),要么将 Node Server 配置为接受 HTTPS 请求。

希望这能回答您的问题。

关于node.js - https如何与http通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com