访问
http://127.0.0.1:40000/aaa/1.txt
,实际访问的是 c:\\bbb\1.txt
。http.Handle("/aaa/", http.StripPrefix("/aaa", http.FileServer(http.Dir("c:\\bbb")))) http.ListenAndServe(":40000", nil)
http.StripPrefix
需要注意,如果不去除 /aaa
,实际是以 c:\\bbb\aaa\\1.txt
路径查找。