How do I configure apache-traffic-server to forward an http request to an https remote server?

筅森魡賤 提交于 2020-01-06 08:12:52

问题


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.

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.

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.

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

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

where 192.168.86.77 is the local address of my raspberry pi.

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>

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

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?

Update:

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

Change:

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

To:

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

where http_ is the instance of the HTTPClient

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/58032103/how-do-i-configure-apache-traffic-server-to-forward-an-http-request-to-an-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!