如何配置 apache-traffic-server 将 http 请求转发到 https 远程服务器?
How do I configure apache-traffic-server to forward an http request to an https remote server?
我有一个 esp8266,它直接向 http://fcm.googleapis.com/fcm/send
发送 http 请求,但是由于 google 似乎已经停止允许通过 http 发送请求,我需要找到一个新的解决方案。
我开始让 esp8266 直接通过 https 发送请求,虽然它在一个小示例上工作,但 https 请求所需的内存占用在我的完整应用程序中太多了,我最终导致 esp8266 崩溃.虽然仍有一些方法可以让我继续直接向服务器发送消息,但我想我想通过 http 将请求发送到本地 "server" raspberry pi 来解决这个问题,并让其通过 https 发送请求。
虽然我可以 运行 一个小型网络服务器和一些代码来处理请求,但这似乎正是 traffic-server 应该能够为我做的事情。
我认为这应该是一个班轮。我在 remap.config
文件中添加了以下内容。
redirect http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send
其中 192.168.86.77
是我的 raspberry pi.
的本地地址
当我向 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 的实例
并且在我的 raspberry pi 上安装 trafficserver 之后,我需要将以下两行添加到 /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
请注意,仅当您想从 fcm 获得反馈时才需要 reverse_map
行,即 post 是否成功。
我会尝试一些改变:
- 我会使用地图:
map http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send
而不是重定向。 redirect
旨在向您的客户发送 301,然后您的客户会跟随它,这听起来会破坏您的目的。 map 应该让 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"
,这样端口就不是重新映射的一部分。
我有一个 esp8266,它直接向 http://fcm.googleapis.com/fcm/send
发送 http 请求,但是由于 google 似乎已经停止允许通过 http 发送请求,我需要找到一个新的解决方案。
我开始让 esp8266 直接通过 https 发送请求,虽然它在一个小示例上工作,但 https 请求所需的内存占用在我的完整应用程序中太多了,我最终导致 esp8266 崩溃.虽然仍有一些方法可以让我继续直接向服务器发送消息,但我想我想通过 http 将请求发送到本地 "server" raspberry pi 来解决这个问题,并让其通过 https 发送请求。
虽然我可以 运行 一个小型网络服务器和一些代码来处理请求,但这似乎正是 traffic-server 应该能够为我做的事情。
我认为这应该是一个班轮。我在 remap.config
文件中添加了以下内容。
redirect http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send
其中 192.168.86.77
是我的 raspberry pi.
当我向 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 的实例
并且在我的 raspberry pi 上安装 trafficserver 之后,我需要将以下两行添加到 /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
请注意,仅当您想从 fcm 获得反馈时才需要 reverse_map
行,即 post 是否成功。
我会尝试一些改变:
- 我会使用地图:
map http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send
而不是重定向。 redirect
旨在向您的客户发送 301,然后您的客户会跟随它,这听起来会破坏您的目的。 map 应该让 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"
,这样端口就不是重新映射的一部分。