just serve static files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Moritz Marquardt ff662e5526
Add systemd service file for non-docker deployment
2 months ago
cmd Make it usable as a library with middlewares 7 months ago
.drone.yml Make a tiny change to trigger a Drone CI build 1 year ago
.gitignore Release first & final version 1 year ago
Dockerfile Make it usable as a library with middlewares 7 months ago
LICENSE Make the application available under the EUPL v1.2 license 7 months ago
README.md Clarify usage of Cache-Control header 7 months ago
go.mod Update dependencies 2 months ago
server.go Make it usable as a library with middlewares 7 months ago
web.service Add systemd service file for non-docker deployment 2 months ago

README.md

web: just serve static files.

This is a Docker image that's built for exactly a single thing: serving static files. Use it for your JAMstack applications, to serve your .well-known directory for Let's Encrypt, local development, or basically anything else that just requires a simple file server. It's built in under 100 lines of Go, using the awesome fasthttp library for extreme efficiency.

To get started, just run the following command to serve the current working directory on http://localhost:8080:

docker run --rm -it -p 8080:80 -v "$PWD:/var/www:ro" momar/web

The following options (each shown with their default value) are configurable through environment variables (-e VARIABLE=value):

  • NOT_FOUND=/404.html - path to the 404 error page
  • NOT_FOUND_STATUS=404 - set a status code for the 404 error page (you can use "200" here for webapps based on the history API)
  • INDEX_FILES=index.html;index.htm - semicolon-separated list of files that should be served when accessing a directory
  • ENABLE_INDEX=0 - show a directory index if no index file could be found
  • ENABLE_HIDDEN=0 - allow access to files and directories starting with a dot
  • ENABLE_COMPRESSION=1 - enable gzip/deflate/brotli compression on-the-fly; you can also use the special value cached to create cached .fasthttp.gz files, which is recommended when extending the image via a Dockerfile, and is not recommended when using volumes
  • ENABLE_RANGE=1 - enable HTTP range requests
  • ENABLE_CORS=0 - enable CORS headers with Origin: *, Headers: Range and Methods: GET, HEAD
  • ENABLE_CACHE=1 - if set to 0, send a Cache-Control: no-cache header with each request (otherwise it will be set to must-revalidate)
  • ENABLE_DEBUG=0 - print all non-OK requests to standard output/docker logs
  • HOST=[::] & PORT=80 - listening address, doesn't normally have to be changed

I'm assuming that you're using Docker with a reverse proxy anyways if you want to use this, so this doesn't come with HTTPS support - if you need that, go with Caddy, or add a Traefik 2 to your setup.

This image is feature-complete and production-ready, and has been inspired by hastatic (which is unfortunately written in a really ugly programming language).

Also, doing a quick benchmark on a relatively bad computer with siege -b -c 100 -t 60S and access logs disabled on the example index.html file, it's extremely fast:

Server Compressed image size Requests per second Response time Longest transaction Memory consumption
momar/web 2 MB 5196.34 0.02 s 0.22 s ~11 KB
abhin4v/hastatic 5 MB 2466.33 0.04 s 0.25 s ~220 MB
nginx:alpine 9 MB 5272.68 0.02 s 0.32 s ~14 KB
httpd:alpine 32 MB 4555.74 0.02 s 0.30 s ~30 KB
caddy:alpine 14 MB 4400.65 0.02 s 0.28 s ~ 40 KB