请考虑以下设计情况:我使用两个远程HTTP代理http://proxy1:8181
和http://proxy2:8282
,并且有一个应用程序使用以下各项对各个外部端点执行GET
和POST
一次其中之一。
这些代理端点是随机片状的,值得庆幸的是一次。我正在寻找在这两种方法之间使用工作端点的方法。一种故障转移机制。
这就是我想要做的:设置一个监听http://127.0.0.1:8000
的守护进程,并定期循环检查proxy1
和proxy2
。如果状况良好,则使用proxy1
路由传入的请求,如果不健康,则使用proxy2
路由。
说起来容易做起来难!
不确定是否存在用于Fwd Proxies的负载平衡器-无论如何,寻找指针和任何帮助将不胜感激!
我希望最好在Golang中做到这一点,接下来的选择是C。首先,这不像给出301
那样简单,还可以安抚SO的show me the code so far
:
package main
import (
"log"
"net/http"
)
const (
port = "8000"
)
func main() {
listen := ":" + port
go http.HandleFunc("/", redir)
log.Fatal(http.ListenAndServe(listen, nil))
}
func redir(w http.ResponseWriter, r *http.Request) {
log.Println("Hello there!")
http.Redirect(w, r, "http://pi3/cameras/", 301)
}
如我所见:
$ wget -e http_proxy="http://arrow:8000/" -S -O /dev/null http://moooh/cameras/ -d
<snip>
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: http://pi3/cameras/
Date: Sat, 12 Oct 2019 03:57:00 GMT
Content-Length: 54
URI content encoding = ‘utf-8’
Location: http://pi3/cameras/ [following]
Skipping 54 bytes of body: [<a href="http://pi3/cameras/">Moved Permanently</a>.
] done.
URI content encoding = None
20 redirections exceeded. // <<<<
<snip>