15 个简单、有趣而实用的 单行 HTTP Server

不少语言或服务开发框架都内置了简单的 Web Server 供我们方便的调试使用。比如有时候我们需要调试单个 PHP 页面而不想搭建一套完整的 PHP 环境,亦或者我们只是临时的共享一下文件而不想搭建一套完整的 Web 服务器或者 FTP,那么本文讲述的这些简单、有趣而实用的的 One Line HTTP Server 或许能让你大开眼界~

1、Python 2.x

python -m SimpleHTTPServer 8000

-- Python 3.x:

python -m http.server 8000

2、Twisted (Python)

twistd -n web -p 8000 --path .

-- or:

python -c 'from twisted.web.server import Site; from twisted.web.static import File; from twisted.internet import reactor; reactor.listenTCP(8000, Site(File("."))); reactor.run()'

3、Ruby

ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'

-- Ruby 1.9.2+

ruby -run -ehttpd . -p8000

4、adsf (Ruby)

gem install adsf   # install dependency
adsf -p 8000

5、Sinatra (Ruby)

gem install sinatra   # install dependency
ruby -rsinatra -e'set :public_folder, "."; set :port, 8000'

6、Perl

cpan HTTP::Server::Brick   # install dependency
perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'

7、Plack (Perl)

cpan Plack   # install dependency
plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000

8、Mojolicious (Perl)

cpan Mojolicious::Lite   # install dependency
perl -MMojolicious::Lite -MCwd -e 'app->static->paths->[0]=getcwd; app->start' daemon -l http://*:8000

9、http-server (Node.js)

npm install -g http-server   # install dependency
http-server -p 8000

10、node-static (Node.js)

npm install -g node-static   # install dependency
static -p 8000

11、PHP (>= 5.4)

php -S 127.0.0.1:8000

-- 需要 -t 指定 root dir 或者启动目录下创建 index.php:<?php phpinfo(); ?> 来测试效果

12、Erlang

erl -s inets -eval 'inets:start(httpd,[{server_name,"NAME"},{document_root, "."},{server_root, "."},{port, 8000},{mime_types,[{"html","text/html"},{"htm","text/html"},{"js","text/javascript"},{"css","text/css"},{"gif","image/gif"},{"jpg","image/jpeg"},{"jpeg","image/jpeg"},{"png","image/png"}]}]).'

13、busybox httpd

busybox httpd -f -p 8000

14、webfs

webfsd -F -p 8000

15、IIS Express

C:\> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\MyWeb /port:8000

 

Refer:

[1] Big list of http static server one-liners

https://gist.github.com/willurd/5720255

[2] 300行python代码的轻量级HTTPServer实现文件上传下载

http://my.oschina.net/leejun2005/blog/71444

转载于:https://my.oschina.net/leejun2005/blog/675481

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值