若是想創建一個簡單靜態文件或目錄服務器,一般能夠用 Python 實現,並且很是簡單python
# Python 2 python -m SimpleHTTPServer <port> # Python 3 python3 -m http.server <port>
通常狀況下,這就夠用了,但若是這樣的服務器在瀏覽器提供的界面有些簡陋,並且不提供認證服務。更復雜
的實現方法是使用 Nginx,但 Nginx 的配置相對繁瑣,這裏推薦一個使用 Rust 基於 Actix
框架實現靜態文件或文件夾服務器 miniserve,demo以下linux
除了更加漂亮的界面和基本用戶認證外 miniserve 還支持以下功能git
在發行版界面找到操做系統對應的版本,文件很小,最大的 osx 也僅有 3.2MB。github
sudo curl -L https://github.com/svenstaro/miniserve/releases/download/v0.4.1/miniserve-linux-x86_64 -o /usr/local/bin/miniserve sudo chmod +x /usr/local/bin/miniserve
sudo curl -L https://github.com/svenstaro/miniserve/releases/download/v0.4.1/miniserve-osx-x86_64 -o /usr/local/bin/miniserve sudo chmod +x /usr/local/bin/miniserve
windows 下載好 exe 文件可直接運行docker
若是電腦上安裝了 Rust 和 Cargo,也能夠經過 Cargo 安裝,但因爲 miniserve
僅支持 nightly channel,因此你得先切換到 nightly channelwindows
rustup add toolchain nightly rustup default nightly cargo install miniserve
miniserve 在 docker hub 上的鏡像名爲 svenstaro/miniserve瀏覽器
docker pull svenstaro/miniserve
所有參數以下bash
miniserve --help miniserve 0.4.1 Sven-Hendrik Haase <svenstaro@gmail.com>, Boastful Squirrel <boastful.squirrel@gmail.com> For when you really just want to serve some files over HTTP right now! USAGE: miniserve [FLAGS] [OPTIONS] [--] [PATH] FLAGS: -u, --upload-files Enable file uploading -h, --help Prints help information -P, --no-symlinks Do not follow symbolic links -o, --overwrite-files Enable overriding existing files during file upload --random-route Generate a random 6-hexdigit route -V, --version Prints version information -v, --verbose Be verbose, includes emitting access logs OPTIONS: -a, --auth <auth> Set authentication (username:password) -c, --color-scheme <color_scheme> Default color scheme [default: Squirrel] [possible values: Archlinux, Zenburn, Monokai, Squirrel] -i, --if <interfaces>... Interface to listen on -p, --port <port> Port to use [default: 8080] ARGS: <PATH> Which path to serve
miniserve some_dir
miniserve file
--auth user:passwd
能夠提供簡單用戶認證服務服務器
miniserve --auth joe:123 some_dir
miniserve -i 192.168.0.1 --random-route some_dir # 服務器URL爲 http://192.168.0.1/c78b6
miniserve -i 192.168.0.1 -i 10.13.37.10 -i ::1 some_dir
# 後臺運行 docker run -d --name miniserve -p 8080:8080 --rm svenstaro/miniserve some_dir # 前臺運行 docker run --it --name miniserve -p 8080:8080 --rm svenstaro/miniserve some_dir