go mod tidy 报错:x509: certificate signed by unknown authority 最佳实践

最近在docker中运行了一个ubuntu20的系统,在上面运行golang程序,使用go mod tidy后报错:

tls: failed to verify certificate: x509: certificate signed by unknown authority

如:

bash 复制代码
go: finding module for package google.golang.org/grpc/credentials/insecure
go: finding module for package github.com/shopspring/decimal
go: finding module for package github.com/stretchr/testify/assert
go: metag_media_server/app imports
	github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://goproxy.cn/github.com/gin-gonic/gin/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/config imports
	github.com/pkg/errors: module github.com/pkg/errors: Get "https://goproxy.cn/github.com/pkg/errors/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/config imports
	github.com/spf13/viper: module github.com/spf13/viper: Get "https://goproxy.cn/github.com/spf13/viper/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/controller imports
	github.com/axetroy/go-fs: module github.com/axetroy/go-fs: Get "https://goproxy.cn/github.com/axetroy/go-fs/@v/list": tls: failed to verify certificate: x509: certificate signed by unknown authority
go: metag_media_server/app/controller imports

出现这中情况一般都是自己安装全新的ubuntu系统,或者在docker中安装ubuntu镜像,跟我一样。

在网上找了很多资料,都没有解决。

这里提供两种最佳方案:

一:设置http的goproxy

bash 复制代码
export GOPROXY=http://goproxy.cn

或者

export GOPROXY=http://mirrors.aliyun.com/goproxy/

注意前缀不是https

二:重装ca-certificates

bash 复制代码
sudo apt-get install --reinstall ca-certificates
sudo apt-get update

之后就可以愉快的使用go mod tidy了

相关推荐
MY_TEUCK13 分钟前
【Java 后端】SpringBoot 登录认证与会话跟踪实战(JWT + Filter/Interceptor)
java·开发语言·spring boot
QQ24221997925 分钟前
基于python+微信小程序的家教管理系统_mh3j9
开发语言·python·微信小程序
沐知全栈开发1 小时前
JavaScript 条件语句
开发语言
RSTJ_16251 小时前
PYTHON+AI LLM DAY THREETY-SEVEN
开发语言·人工智能·python
清水白石0081 小时前
《Python性能深潜:从对象分配开销到“小对象风暴”的破解之道(含实战与最佳实践)》
开发语言·python
Je1lyfish1 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
Brilliantwxx2 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
野生技术架构师2 小时前
2026年最全Java面试题及答案汇总(建议收藏,面试前看这篇就够了)
java·开发语言·面试
程序员飞哥2 小时前
重构 AI 思维(一):Prompt Engineering,如何下达不可违抗的指令?
人工智能·后端
百锦再2 小时前
Auto.js变成基础知识学习
开发语言·javascript·学习·sqlite·kotlin·android studio·数据库开发