# Static Web Server [](https://travis-ci.com/joseluisq/static-web-server) [](https://microbadger.com/images/joseluisq/static-web-server "Get your own image badge on microbadger.com") [](https://hub.docker.com/r/joseluisq/static-web-server/)
> A blazing fast static files-serving web server powered by [Rust Iron](https://github.com/iron/iron). :zap:
**Static Web Server** is a very small and fast web server to serving static files such as html files or assets.
## Features
- Built with [Rust](https://rust-lang.org) which is focused on [safety, speed, and concurrency](https://kornel.ski/rust-c-speed).
- Memory safety and reduced overhead of CPU and RAM resources.
- Blazing fast static files-serving thanks to [Rust Iron](https://github.com/iron/iron).
- Suitable for small [GNU/Linux Docker containers](https://hub.docker.com/r/joseluisq/static-web-server). It's a fully __1.4MB__ static binary thanks to [Rust and Musl libc](https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html).
- Gzip compression by default.
- Cache control headers included.
- Configurable via environment variables or CLI arguments.
- Lightweight logging support.
- Scratch and [latest Alpine Linux](https://hub.docker.com/_/alpine) Docker images available.
## Missing features
- TLS support
PRs welcome!
## Usage
Server is configured either via environment variables:
- **SERVER_NAME**: Name for server. Default `my-static-server`.
- **SERVER_HOST**: Host address (E.g 127.0.0.1). Default `[::]`.
- **SERVER_PORT**: Host port. Default `80`.
- **SERVER_ROOT**: Root directory path of static files. Default `./public`.
- **SERVER_ASSETS**: Assets directory path for add cache headers functionality. Default `./assets` but relative to the root.
- **SERVER_ERROR_PAGE_404**: HTML file path for 404 errors. Default `./public/404.html`.
- **SERVER_ERROR_PAGE_50X**: HTML file path for 50x errors. Default `./public/50x.html`.
Or command line arguments listed with `cargo run -- -h`.
```sh
static-web-server 1.0.0
USAGE:
static-web-server [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--assets <assets> Assets directory path for add cache headers functionality [env: SERVER_ASSETS=]
[default: ./assets]
--host <host> Host address (E.g 127.0.0.1) [env: SERVER_HOST=] [default: [::]]
--name <name> Name for server [env: SERVER_NAME=] [default: my-static-server]
--page404 <page404> HTML file path for 404 errors [env: SERVER_ERROR_PAGE_404=] [default: ./public/404.html]
--page50x <page50x> HTML file path for 50x errors [env: SERVER_ERROR_PAGE_50X=] [default: ./public/50x.html]
--port <port> Host port [env: SERVER_PORT=] [default: 80]
--root <root> Root directory path of static files [env: SERVER_ROOT=] [default: ./public]
```
## Docker stack
Example using [Traefik proxy](https://traefik.io/):
```yaml
version: "3.3"
services:
web:
image: joseluisq/static-web-server:latest
environment:
- SERVER_NAME=my-server
- SERVER_HOST=127.0.0.1
- SERVER_PORT=8080
- SERVER_ROOT=/html
- SERVER_ASSETS=./assets
volumes:
- ./some-dir-path:/html
labels:
- "traefik.enable=true"
- "traefik.frontend.entryPoints=https"
- "traefik.backend=localhost_dev"
- "traefik.frontend.rule=Host:localhost.dev"
- "traefik.port=80"
networks:
- traefik_net
networks:
traefik_net:
external: true
```
## Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.
Feel free to send some [Pull request](https://github.com/joseluisq/static-web-server/pulls) or [issue](https://github.com/joseluisq/static-web-server/issues).
## License
This work is primarily distributed under the terms of both the [MIT license](LICENSE-MIT) and the [Apache License (Version 2.0)](LICENSE-APACHE).
© 2019 [Jose Quintana](https://git.io/joseluisq)