简体   繁体   中英

golang local reverse proxy is rejected

func main() {
    http.HandleFunc("/a", func(writer http.ResponseWriter, request *http.Request) {
        remote, _ := url.Parse("http://localhost:9000")
        proxy := httputil.NewSingleHostReverseProxy(remote)
        proxy.ServeHTTP(writer, request)
    })
 
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        fmt.Println(err)
    }
}

In the local environment of reverse proxy prompt

http: proxy error: dial tcp 127.0.0.1:9000: connect: connection refused.

Firewall has been turned off. Can you tell me how to solve?

Check if the URL http://localhost:9000 is working in your local. If that's not working, it may be down. If the http server is running on 9000 port, it will work.

If still not working, share the code details about http://localhost:9000 URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM