返回排行榜

TheWaWaR/simple-http-server

Rust

Simple http server in Rust (Windows/Mac/Linux)

staticfileserversimplehttpserverhttprust
Star 增长趋势
Star
3.4k
Forks
216
周增长
Issues
38
1k2k3k
2017年5月2020年5月2023年6月2026年7月
制品库crates.iocargo add simple-http-server
README

Simple HTTP Server

Simple static file server with directory listing, upload, basic auth, range requests, compression, CORS, SPA fallback, and optional PKCS#12 HTTPS support.

The current implementation is based on axum/tokio. TLS support is behind the tls feature and is disabled by default so the default binary stays smaller.

Screenshot

Installation

Default build:

cargo install simple-http-server

With PKCS#12 HTTPS support:

cargo install simple-http-server --features tls

Usage

Usage: simple-http-server [OPTIONS] [root]

Arguments:
  [root]  Root directory

Options:
  -i, --index                     Enable automatic render index page [index.html, index.htm]
  -u, --upload                    Enable upload files. (multiple select) (CSRF token required)
      --csrf <TOKEN>              Use a custom CSRF token for upload. WARNING: this is dangerous as the token is passed via the command line and may be visible in process listings
      --redirect <URL>            takes a URL to redirect to using HTTP 301 Moved Permanently
      --nosort                    Disable directory entries sort (by: name, modified, size)
      --nocache                   Disable http cache
      --norange                   Disable header::Range support (partial request)
      --cert <FILE>               TLS/SSL certificate (pkcs#12 format, requires tls feature)
      --cors                      Enable CORS via the "Access-Control-Allow-Origin" header
      --coop                      Add "Cross-Origin-Opener-Policy" HTTP header and set it to "same-origin"
      --coep                      Add "Cross-Origin-Embedder-Policy" HTTP header and set it to "require-corp"
      --certpass <PASSWORD>       TLS/SSL certificate password (requires tls feature)
  -l, --upload-size-limit <SIZE>  Upload file size limit [bytes, or K/M/G/T suffix interpreted with powers of 1024, such as 30K, 50M, 1G] [default: 8M]
      --ip <IP>                   IP address to bind [default: 0.0.0.0]
  -p, --port <PORT>               Port number [default: 8000]
  -a, --auth <USER:PASS>          HTTP Basic Auth (username:password)
  -c, --compress <EXT>...         Enable file compression: gzip/deflate
                                  Example: -c=js,d.ts
                                  Note: disabled on partial request!
  -t, --threads <NUM>             How many worker threads [default: 3]
      --try-file <PATH>           Serve this file in place of missing paths. Relative paths are resolved against the server root; absolute paths are used as-is. [aliases: --try-file-404]
  -s, --silent                    Disable all outputs
  -o, --open                      Open the page in the default browser
  -b, --base-url <PATH>           Base URL prefix for directory indexes and upload redirects. It is normalized to start with '/' and to end with '/' when not root. [default: /]
  -h, --help                      Print help
  -V, --version                   Print version

Examples

Serve a folder:

simple-http-server -i public

Enable upload and raise the upload limit:

simple-http-server -u -l 50M .

Serve an SPA fallback file:

simple-http-server --try-file dist/index.html dist

Run behind a reverse proxy that strips /static/ before forwarding:

simple-http-server --base-url /static/ .

HTTPS Example

--cert expects a PKCS#12 file such as .p12 or .pfx. PEM files are not accepted directly.

1. Generate a local certificate and .p12

mkdir -p /tmp/simple-http-server-tls
cd /tmp/simple-http-server-tls

openssl req \
  -x509 \
  -newkey rsa:2048 \
  -nodes \
  -sha256 \
  -keyout key.pem \
  -out cert.pem \
  -days 7 \
  -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost"

openssl pkcs12 \
  -export \
  -inkey key.pem \
  -in cert.pem \
  -out localhost.p12 \
  -passout pass:changeit

2. Start the server

simple-http-server \
  -i \
  --ip 127.0.0.1 \
  --port 8443 \
  --cert /tmp/simple-http-server-tls/localhost.p12 \
  --certpass changeit \
  .

3. Verify it

Strict verification:

curl --fail --silent --show-error \
  --cacert /tmp/simple-http-server-tls/cert.pem \
  https://localhost:8443/

Quick local smoke test:

curl -kI https://localhost:8443/

Features

  • Directory listing with breadcrumb navigation
  • Optional index.html / index.htm rendering
  • File upload with CSRF protection
  • HTTP Basic Auth
  • HTTP cache control with Last-Modified and ETag
  • Single-range partial content support
  • gzip / deflate compression
  • CORS plus COOP / COEP headers
  • SPA fallback via --try-file
  • Optional PKCS#12 HTTPS via the tls feature
相关仓库
vercel/next.js

The React Framework

JavaScriptnpmMIT Licensereactserver-rendering
nextjs.org
141.1k31.5k
withastro/astro

The web framework for content-driven websites. ⭐️ Star to support our work!

TypeScriptnpmOtherstatic-site-generatorblog
astro.build
61.2k3.6k
decaporg/decap-cms

A Git-based CMS for Static Site Generators

JavaScriptnpmMIT Licensecmsjamstack
decapcms.org
19.3k3.1k
getzola/zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org

Rustcrates.ioEuropean Union Public License 1.2staticsite-generator
getzola.org
17.3k1.2k
http-party/http-server

A simple, zero-configuration, command-line http server

JavaScriptnpmMIT Licensehttpstatic
14.2k1.6k
react-static/react-static

⚛️ 🚀 A progressive static site generator for React.

JavaScriptnpmMIT Licensereactreact-static
github.com/react-static/react-static/discussions
10.3k742
apex/up

Deploy infinitely scalable serverless apps, apis, and sites in seconds to AWS.

GoGo ModulesMIT Licensedeploymentaws
up.docs.apex.sh
8.8k385
robinmoisson/staticrypt

Password protect a static HTML page, decrypted in-browser in JS with no dependency. No server logic needed.

HTMLMIT Licensestatic-htmlencryption
robinmoisson.github.io/staticrypt/
8k495
detekt/detekt

Static code analysis for Kotlin

MDXApache License 2.0staticanalysis
detekt.dev
7k847
carp-lang/Carp

A statically typed lisp, without a GC, for real-time applications.

HaskellApache License 2.0lisplanguage
6k185
nunomaduro/phpinsights

🔰 Instant PHP quality checks from your console

PHPPackagistMIT Licensephpstatic
youtube.com/@nunomaduro
5.6k296
saicaca/fuwari

✨A static blog template built with Astro.

AstroMIT Licenseastroblog
fuwari.vercel.app
4.8k1.2k