| id | fileserver |
|---|---|
| title | π File Server |
| sidebar_position | 9 |
Fiber ships with a configurable file server located in the cmd/fileserver
directory. It can serve static files from any directory and supports TLS for
secure connections. The server is also available via the fiber serve command.
You can still run the program directly with go run ./cmd/fileserver or build
it using go build -o fileserver ./cmd/fileserver.
Run the command specifying the directory and optional TLS certificate and key files:
fiber serve -dir ./public -addr :8443 -cert cert.pem -key key.pem-dirβ directory to serve (default.)-addrβ address to listen on (default:3000)-pathβ URL path to mount the directory (default/)-loggerβ enable request logging (defaulttrue)-corsβ enable CORS middleware-healthβ expose/livez,/readyzand/startupzendpoints (defaulttrue)-certβ path to TLS certificate file-keyβ path to TLS private key file-browseβ enable directory listing-downloadβ force file downloads instead of in-browser viewing-compressβ enable serving of pre-compressed assets-cacheβ cache duration (e.g.30s)-maxageβ Cache-Control max-age in seconds-indexβ comma-separated list of index files-rangeβ enable byte range requests-preforkβ start server in prefork mode-quietβ disable the startup banner
When both -cert and -key are provided the server automatically enables TLS.