Middle+
What is a reverse proxy and what is usually used to implement it?
sobes.tech AI
Answer from AI
A reverse proxy is a server that accepts requests from clients and forwards them to one or more internal servers. It hides the internal network structure, load balances, caches responses, and provides security.
Common tools for implementing a reverse proxy include:
- Nginx — a popular web server with powerful proxying and load balancing capabilities.
- HAProxy — a specialized load balancer and proxy.
- In Go, you can use the
net/httppackage to create your own reverse proxy, for example, throughhttputil.ReverseProxy.
Example of a simple reverse proxy in Go:
package main
import (
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
target, _ := url.Parse("http://localhost:8080")
proxy := httputil.NewSingleHostReverseProxy(target)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
proxy.ServeHTTP(w, r)
})
http.ListenAndServe(":9090", nil)
}