首页 > 解决方案 > 如何配置 apache-traffic-server 以将 http 请求转发到 https 远程服务器?

问题描述

我有一个 esp8266,它直接向其发送 http 请求,http://fcm.googleapis.com/fcm/send但由于谷歌似乎已经停止允许通过 http 发送请求,我需要找到一个新的解决方案。

我开始让 esp8266 通过 https 直接发送请求,虽然它适用于一个小例子,但 https 请求所需的内存占用在我的完整应用程序中非常多,我最终导致 esp8266 崩溃。虽然仍然有一些途径可以让我继续直接向服务器发送消息,但我想我想通过将请求通过 http 发送到本地“服务器”树莓派来解决这个问题,然后发送通过 https 请求。

虽然我可以运行一个小型 Web 服务器和一些代码来处理请求,但这似乎正是交通服务器应该能够为我做的事情。

我认为这应该是一个班轮。我在文件中添加了以下内容remap.config

redirect http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send

192.168.86.77我的树莓派的本地地址在哪里。

当我向我发送请求时,http://192.168.86.77/fcm/send:8080我得到以下信息:

HTTP/1.1 404 Not Found
Date: Fri, 20 Sep 2019 16:22:14 GMT
Server: Apache/2.4.10 (Raspbian)
Content-Length: 288
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /fcm/send:8080 was not found on this server.</p>
<hr>
<address>Apache/2.4.10 (Raspbian) Server at localhost Port 80</address>
</body></html>

我认为 8080 是正确的端口。我猜这不是我认为应该的一个班轮。

这是否适合 apache-traffic-controller?有人可以指出我做错了什么以及实现目标的正确方法是什么?

更新:

根据下面的 Miles Libbey 回答,我需要对 Arduino/esp8266 代码进行以下更新。

改变:

http_.begin("http://fcm.googleapis.com/fcm/send");

到:

http_.begin("192.168.86.77", 8080, "http://192.168.86.77/fcm/send");

其中 http_ 是 HTTPClient 的实例

在我的树莓派上安装交通服务器后,我需要将以下两行添加到/etc/trafficserver/remap.config

map http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send
reverse_map https://fcm.googleapis.com/fcm/send http://192.168.86.77/fcm/send

请注意,reverse_map仅当您想从 fcm 获得反馈时才需要该行,即帖子是否成功。

标签: firebase-cloud-messagingapache-traffic-server

解决方案


我会尝试一些更改: - 我会使用 map: map http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send而不是重定向。这redirect意味着向您的客户发送 301,然后您的客户会跟随它,这听起来会破坏您的目的。地图应该有 ATS 做代理。- 我认为你的 curl 可能已经关闭 - 端口通常在域部分之后 - 例如,curl "http://192.168.86.77:8080/fcm/send". (并且可能更好: curl -x 192.168.86.77:8080 "http://192.168.86.77:8080/fcm/send",以便端口不是重新映射的一部分。


推荐阅读