golang代理轉發基礎
go標準庫已經實現了一個反向代理工具,通過代理將客戶端的請求轉發到代理服務器。
什麼是反向代理?
維基百科解釋:
”In computer networks , a reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, appearing as if they originated from the proxy server itself. “
中文釋義:
在計算機網絡中,反向代理是一種代表客戶端從一個或多個服務器上檢索資源的代理服務器,這些資源最後會返回給客戶端,看起來就好像他們來自代理服務器本身。
從本質上說,反向代理是將流量從客戶端轉發到代理後面的服務器。反向代理有很多應用,比如負載均衡、TLS終止和A/B測試。反向代理還可以在Http服務周圍嵌入工具,而不修改服務本身。
簡單的反向代理
Go標準庫自帶反向代理的實現,它就是httputil
。它的簡單使用如下:
proxy