I was setting up a file server handler for certbot using net/http
's FileServer
handler and ran into some odd behavior setting the file server's root directory to a hidden directory.
I have a directory structure as follows:
certbot/
|- .well-known/
| |- test.txt
|- well-known/
|- test.txt
All with the same user/group/permissions.
The following handler fails to serve test.txt (returns a 404 for GET /.well-known/test.txt):
http.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir("./certbot/.well-known"))))
However, these both work:
http.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir("./certbot/well-known"))))
http.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir("./certbot/.well-known/"))))
I'm wondering why I have to add the trailing slash when serving from ./certbot/.well-known
but not from ./certbot/well-known
. I don't see anything in the net/http source code that would cause this. The http.Dir documentation states that it will allow access to directories that begin with a period. Why is the trailing slash needed in the one handler but not the other?
I'm using go v1.9.2 on a CentOS 7 Digital Ocean droplet.