若是想创建一个简单静态文件或目录服务器,一般能够用 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