Sobes.tech
Middle+

Mis on reverse-proxy ja mida tavaliselt selle rakendamiseks kasutatakse?

sobes.tech AI

Vastus AI-lt

Reverse-proxy on server, which receives requests from clients and redirects them to one or more internal servers. It hides the internal network structure, balances the load, caches responses, and ensures security.

Commonly used tools for implementing reverse-proxy include:

  • Nginx — a popular web server with powerful proxy and load balancing capabilities.
  • HAProxy — a specialized load balancer and proxy.
  • In Go, you can use the net/http package to create your own reverse-proxy, for example, using httputil.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)
}