解决部署golang项目后文件无法访问 出现 404 404 page not found

运行golang项目后文件无法访问 出现 404 404 page not found

func main() {
	fmt.Println("Linwute 2022-07-29")

	//解决静态文件访问 404
	//http.Handle("/", http.FileServer(http.Dir("./upload"))) //根目录方式

	//访问服务器目录./public文件夹里的内容,可以通过 http://localhost:3000/static来进行访问。
	http.Handle("/upload/", http.StripPrefix("/upload/", http.FileServer(http.Dir("./upload"))))
	http.Handle("/file/", http.StripPrefix("/file/", http.FileServer(http.Dir("./file"))))

  //... 其他业务代码
}

部署golang项目 图片和文件无法访问
通过链接 golang项目下文件夹的 图片和文件无法访问
出现 404 404 page not found

1,135 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注