简单的文件服务器服务当前目录
我正在寻找一个死的简单的bin,我可以在shell中启动,并提供当前目录(最好不是..),也许用-p
指定端口。 因为它应该是一个开发服务器,它应该默认允许只从本地主机连接,也许有一个选项来指定,否则。 越简单越好。
不确定在这里使用哪个标签。
python3 -m http.server
或者如果您不想使用默认端口8000
python3 -m http.server 3333
或者是否只允许从本地主机连接
python3 -m http.server --bind 127.0.0.1
看文档 。
等效的Python 2命令是
python -m SimpleHTTPServer python -m SimpleHTTPServer 3333
没有 – --bind
选项。
请参阅Python 2文档 。
对于Node,有http-server
:
$ npm install -g http-server $ http-server Downloads -a localhost -p 8080 Starting up http-server, serving Downloads on port: 8080 Hit CTRL-C to stop the server
Python有:
- Python 3 :
python -m http.server --bind 127.0.0.1 8080
- Python 2 :
python -m SimpleHTTPServer 8080
请注意,Python 2没有--bind
选项,所以它将允许所有连接(不只是从localhost
)。
有Perl应用程序App :: HTTPThis或者我经常使用一个微小的Mojolicious服务器来做到这一点。 一会儿见我的博客文章 。
创build一个叫做server.pl
的文件。 把它放在里面。
#!/usr/bin/env perl use Mojolicious::Lite; use Cwd; app->static->paths->[0] = getcwd; any '/' => sub { shift->render_static('index.html'); }; app->start;
安装Mojolicious: curl get.mojolicio.us | sh
然后运行morbo server.pl
。
应该可以工作,如果需要的话你可以调整脚本。
使用Twisted Web :
twistd --pidfile= -n web --path . --port 8080
--pidfile=
禁用PID文件。 没有它,将在当前目录中创build一个twistd.pid
文件。 你也可以使用--pidfile ''
。