Go 和 Hugo 代理服務器

Go 官方的模塊代理服務器被 GFW 牆了,沒有 VPN 的情況下,於國內是無法正常使用的。不過可以通過設置代理服務器解決,本文將列出一些可用的 Go 代理服務器。而這也同樣適用於 Hugo 模塊。

代理服務器

代理服務器URL
GOPROXY.CN (七牛雲)https://goproxy.cn/
GOPROXY.IOhttps://goproxy.io/
阿里雲https://mirrors.aliyun.com/goproxy/
騰訊雲https://mirrors.tencent.com/go/

設置 Go 模塊代理服務器

1go env -w GOPROXY=https://goproxy.cn/,direct
1export GOPROXY=https://goproxy.cn/,direct
1$ENV:GOPROXY="https://goproxy.cn/,direct"

設置 Hugo 模塊代理服務器

與 Go 不同,Hugo 使用 HUGO_MODULE_PROXY 環境變量而非 GOPROXY

hugo.yaml

1module:
2  proxy: https://goproxy.cn,direct

hugo.toml

1[module]
2  proxy = 'https://goproxy.cn,direct'

hugo.json

1{
2   "module": {
3      "proxy": "https://goproxy.cn,direct"
4   }
5}
1export HUGO_MODULE_PROXY=https://goproxy.cn/,direct
1$ENV:HUGO_MODULE_PROXY="https://goproxy.cn/,direct"

詳情請參閱 Module Config.