在 CentOS 上设置 Golang 的代理(通常指 Go 模块代理 GOPROXY,也包含网络出口代理 HTTP/HTTPS Proxy),可按下面场景配置。
export GOPROXY=https://proxy.golang.org,direct
# 国内推荐使用:
export GOPROXY=https://goproxy.cn,direct
go env -w GOPROXY=https://goproxy.cn,direct
查看是否生效:
go env GOPROXY
常用国内代理:
https://goproxy.cnhttps://goproxy.iohttps://mirrors.aliyun.com/goproxy/go env -w GOPRIVATE=git.example.com,github.com/org/private
如果你的服务器必须走代理才能访问外网:
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export NO_PROXY=localhost,127.0.0.1
永久生效(写入 ~/.bashrc 或 /etc/profile):
echo 'export HTTP_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export HTTPS_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
source ~/.bashrc
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go env -u GOPROXY
CentOS 注意:
systemctl stop firewalld
setenforce 0
如果你是指:
可以告诉我具体场景,我给你更精准的配置。