如何配置apache-traffic-server将HTTP请求转发到https远程服务器? [英] How do I configure apache-traffic-server to forward an http request to an https remote server?

查看:163
本文介绍了如何配置apache-traffic-server将HTTP请求转发到https远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个esp8266,它直接将http请求发送到 http://fcm.googleapis.com/fcm/send ,但是由于Google似乎已停止允许通过http发送请求,因此我需要寻找新的解决方案.

I have an esp8266 which was directly sending http requests to http://fcm.googleapis.com/fcm/send but since google seems have stopped allowing requests to be send via http, I need to find a new solution.

我沿着一条路径让esp8266通过https直接发送请求,尽管它只是一个小例子,但在我的整个应用程序中,https请求所需的内存占用量却很大,最终我使esp8266崩溃了.尽管仍有一些方法可以探索,使我能够继续直接将消息发送到服务器,但我想我想通过将请求通过http发送到本地服务器"树莓派来解决此问题,并通过发送通过https请求.

I started down a path to have the esp8266 directly send the request via https and while it works on a small example the memory footprint required for the https request is to much in my full application and I end up crashing the esp8266. While there are still some avenues to explore that might allow me to continue to directly send messages to the server, I think I would like to solve this by sending the request via http to a local "server" raspberry pi, and have that send the request via https.

虽然我可以运行一个小型Web服务器并使用一些代码来处理请求,但看来这正是流量服务器应该能够为我做的事情.

While I could run a small web server and some code to do handle the requests, it seems like this is exactly something traffic-server should be able to do for me.

我认为这应该是一支班轮.我添加了以下 remap.config 文件.

I thought this should be a one liner. I added the following the the remap.config file.

重定向http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send

其中 192.168.86.77 是我的树莓派的本地地址.

where 192.168.86.77 is the local address of my raspberry pi.

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

When I send requests to http://192.168.86.77/fcm/send:8080 I get back the following:

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是正确的端口.我猜这不是我认为应该的那种班轮.

I think 8080 is the right port. I am guessing this is not the one liner I thought it should be.

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

Is this a good fit for apache-traffic-controller? Can someone point me to what I am doing wrong and what is the right way to accomplish my goal?

基于下面的Miles Libbey回答,我需要对Arduino/esp8266代码进行以下更新.

Based on Miles Libbey answer below, I needed to make the following update to the Arduino/esp8266 code.

更改:

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

收件人:

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

其中http_是HTTPClient的实例

where http_ is the instance of the HTTPClient

然后在我的树莓派上安装 trafficserver 之后,我需要将以下两行添加到/etc/trafficserver/remap.config

And after installing trafficserver on the my raspberry pi, I needed to add the following two lines to the /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 行.

Note the reverse_map line is only needed if you want to get feedback from fcm, ie if the post was successful or not.

推荐答案

我会尝试一些更改:-我会用地图:映射http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send 而不是重定向. redirect 的目的是向您的客户发送301,然后您的客户会遵循它,这听起来像是违背了您的意图.地图应由ATS进行代理.-我认为您的卷曲可能已关闭-端口通常在域部分之后-例如 curl"http://192.168.86.77:8080/fcm/send" .(可能更好: curl -x 192.168.86.77:8080"http://192.168.86.77:8080/fcm/send" ,以便该端口不属于重新映射.

I would try a few changes: - I'd use map: map http://192.168.86.77/fcm/send https://fcm.googleapis.com/fcm/send instead of redirect. The redirect is meant to send your client a 301, and then your client would follow it, which sounds like it'd defeat your purpose. map should have ATS do the proxying. - I think your curl may have been off -- the port usually goes after the domain part -- eg, curl "http://192.168.86.77:8080/fcm/send". (and probably better: curl -x 192.168.86.77:8080 "http://192.168.86.77:8080/fcm/send", so that the port isn't part of the remapping.

这篇关于如何配置apache-traffic-server将HTTP请求转发到https远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆