简单文件服务器为当前目录服务

Rea*_*onk 36 ruby python shell perl node.js

我正在寻找一个死的简单bin,我可以在shell中启动并让它服务于当前目录(最好不是..),可能还有一个-p用于指定端口.因为它应该是一个开发服务器,它应该默认只允许来自localhost的连接,也许有一个选项来指定其他方式.越简单越好.

不确定在这里使用哪些标签.

Dav*_*ope 56

python3 -m http.server
Run Code Online (Sandbox Code Playgroud)

或者如果您不想使用默认端口8000

python3 -m http.server 3333
Run Code Online (Sandbox Code Playgroud)

或者如果您只想允许来自localhost的连接

python3 -m http.server --bind 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

查看文档.


等效的Python 2命令是

python -m SimpleHTTPServer

python -m SimpleHTTPServer 3333
Run Code Online (Sandbox Code Playgroud)

没有--bind选择.

请参阅Python 2文档.


如果您的服务器文件没有更改,一旦您编辑并保存它们,请键入refresh您的python控制台.这将更新服务器提供的文件和最新的文件.

  • 还有一个目录参数,以防您不需要当前目录:`python3 -m http.server -d /path/to/web/dir` (3认同)

Ble*_*der 12

对于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
Run Code Online (Sandbox Code Playgroud)

Python有:

  • Python 3:python -m http.server --bind 127.0.0.1 8080
  • Python 2:python -m SimpleHTTPServer 8080

请注意,Python 2没有--bind选项,因此它将允许所有连接(不仅仅是来自localhost).