使用 cURL、HTTPS POST 进行服务器到服务器通信

发布于 2024-12-02 01:55:56 字数 683 浏览 0 评论 0原文

我正在实现服务器到服务器的通信,应该(可能)如下所示:

客户端网络浏览器)<--> (网络应用服务器服务客户端)<--> (服务应用中央服务器

一些客户端请求在本地处理,一些作为远程服务调用(而不是 RPC)执行。向中央服务器的请求格式为HTTPS POST,然后使用cURL发送;服务器回复适当的 JSON 消息。

问题是,我使用的是 HTTPS,每次执行服务查询时都需要一些额外的时间来进行证书验证。可以重复使用 cURL 句柄并发送“保持活动”连接标头,但是..在当前的 MVC 实现中,每个新的客户端请求都会生成 Web 应用程序的新实例(以及相应的服务客户端) - 这意味着,句柄会重新生成初始化并重新建立 https 连接。

因此,出现了以下问题:

  1. 是否有某种方法可以加速此类 HTTPS 请求?例如,在第一次成功连接后以某种方式绕过验证?
  2. 我可以放弃 HTTPS(特别是其耗时的证书检查过程)并结合某些授权方法(Diffie-Hellman)自行加密/解密 POST 和 JSON(例如,使用 mcrypt)吗?
  3. 我是否正在做一些完全错误的事情并且应该立即停止?

谢谢你!

I'm implementing server to server communications that should (probably) look like this:

client (web browser) <--> (web app) server (service client) <--> (service app) central server

Some of the client requests are processed locally and some are performed as remote service calls (not RPC). Request to central server is formatted as HTTPS POST and then sent using cURL; server replies with appropriate JSON message.

Problem is, I'm using HTTPS and it takes some additional time for certificate verification, each time service query is performed. It's possible to re-use cURL handle and send 'keep-alive' connection header, but.. In current MVC implementation, each new client request results in new instance of web app (and corresponding service client) - meaning, handle is re-initialized and https connection is established anew.

So, the following questions arise:

  1. Is there some way to speed-up such HTTPS requests? E.g., somehow bypass verification after first successful connection?
  2. May I forgo HTTPS (specifically, its time-consuming certificate check procedure) and encrypt/decrypt POST and JSON on my own (for example, using mcrypt) in conjunction with some authorization method (Diffie-Hellman)?
  3. Am I doing something completely wrong and should immediately stop?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-12-09 01:55:56

您测量过 HTTPS 连接的开销吗?这真的很重要吗?

如果您想避免为每个请求进行握手,您可以尝试在服务器和中央服务器之间建立持久的安全连接。

您可以使用 SSH 隧道、VPN 等来做到这一点。

编辑:在中央服务器上保持保持活动连接的本地反向 HTTP 代理也是一种选择。

Did you measured the overhead of the HTTPS connection ? Is it really significant ?

If you would like to avoid doing the handshake for each request, you could try setting up a persistent secured connection between the server and the central server.

You could do that with a SSH tunnel, a VPN, etc.

Edit: A local reverse HTTP proxy that maintains a keep-alive connection on the central server would be an option too.

独木成林 2024-12-09 01:55:56
  1. 将请求分批放入队列中,如果可能的话,一次发送 x 个数量。
  2. 您可以发送带有请求的授权密钥,只有服务器和中央服务器可能知道如何组装。但这会使您的实际数据清晰可见,这可能是也可能不是问题。
  3. 并不是说我可以立即看到
  1. Batch the requests up in a queue and send them x number at a time if it is possible
  2. You could send an authorisation key with the request that only the server and central server could possibly know how to assemble. But that would leave your actual data in plain sight, which may or may not be a problem.
  3. Not that I can immediately see
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文