How to handle HTTPS between go reverse proxies

65 views
Skip to first unread message

Van Fury

unread,
Jun 4, 2021, 4:01:14 AM6/4/21
to golang-nuts
Hi,

Am using "net/http/httputil" Reverse proxy and would to make HTTPS forwarding between the two proxy servers. Any help on how to handle HTTPS between the proxy servers instead of HTTP?
Here are a sample of my code.

Proxy A

func main() {
 
  http.HandleFunc("/", proxyPassA)
  server.ListenAndServeTLS(certFile, keyFile)
}

func proxyPassA(res http.ResponseWriter, req  *http.Request) {
 

server := NewServer("127.0.0.1:8080")

ServerB := http://127.0.0.1:10010

  url, _ := url.Parse(ServerB)
  proxy := httputil.NewSingleHostReverseProxy(url)
  proxy.ServeHTTP(res, req)
}


// NewServer - Create a new server
func NewServer(addr string) *http.Server {

    return &http.Server{
        Addr: addr,
        TLSConfig:    tLSConfig(),
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 10 * time.Second,
        IdleTimeout:  120 * time.Second,
    }
}



Proxy B

func main() {
 
  http.HandleFunc("/", proxyPassB)
  server.ListenAndServeTLS(certFile, keyFile)
}

func proxyPassA(res http.ResponseWriter, req  *http.Request) {
 

server := NewServer("127.0.0.1:7070")

remotehttpserver := http://127.0.0.1:6001

  url, _ := url.Parse(remotehttpserver)
  proxy := httputil.NewSingleHostReverseProxy(url)
  proxy.ServeHTTP(res, req)
}


// NewServer - Create a new server
func NewServer(addr string) *http.Server {

    return &http.Server{
        Addr: addr,
        TLSConfig:    tLSConfig(),
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 10 * time.Second,
        IdleTimeout:  120 * time.Second,
    }
}

BR
Fury
Reply all
Reply to author
Forward
0 new messages