在CentOS上配置Golang代理,可以通过设置环境变量来实现。以下是详细的步骤:
如果你需要通过HTTP代理访问互联网,可以设置HTTP_PROXY
和HTTPS_PROXY
环境变量。
export HTTP_PROXY=http://your.proxy.server:port
export HTTPS_PROXY=https://your.proxy.server:port
编辑你的shell配置文件(例如.bashrc
或.bash_profile
),添加以下行:
export HTTP_PROXY=http://your.proxy.server:port
export HTTPS_PROXY=https://your.proxy.server:port
然后重新加载配置文件:
source ~/.bashrc # 或者 source ~/.bash_profile
从Go 1.13开始,引入了GOPROXY
环境变量,用于设置Go模块代理服务器。
export GOPROXY=https://proxy.golang.org,direct
编辑你的shell配置文件(例如.bashrc
或.bash_profile
),添加以下行:
export GOPROXY=https://proxy.golang.org,direct
然后重新加载配置文件:
source ~/.bashrc # 或者 source ~/.bash_profile
你可以通过以下命令验证代理是否配置成功:
curl -x http://your.proxy.server:port http://www.example.com
curl -x https://your.proxy.server:port https://www.example.com
go env GOPROXY
export HTTP_PROXY=http://username:password@your.proxy.server:port
export HTTPS_PROXY=https://username:password@your.proxy.server:port
通过以上步骤,你应该能够在CentOS上成功配置Golang代理。