前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >15 个简单、有趣而实用的 单行 HTTP Server

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

作者头像
用户1177713
发布2018-02-24 17:45:34
2.7K0
发布2018-02-24 17:45:34
举报
文章被收录于专栏:数据之美数据之美

不少语言或服务开发框架都内置了简单的 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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、Python 2.x
  • 2、Twisted (Python)
  • 3、Ruby
  • 4、adsf (Ruby)
  • 5、Sinatra (Ruby)
  • 6、Perl
  • 7、Plack (Perl)
  • 8、Mojolicious (Perl)
  • 9、http-server (Node.js)
  • 10、node-static (Node.js)
  • 11、PHP (>= 5.4)
  • 12、Erlang
  • 13、busybox httpd
  • 14、webfs
  • 15、IIS Express
  • Refer:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档