不少语言或服务开发框架都内置了简单的 Web Server 供我们方便的调试使用。比如有时候我们需要调试单个 PHP 页面而不想搭建一套完整的 PHP 环境,亦或者我们只是临时的共享一下文件而不想搭建一套完整的 Web 服务器或者 FTP,那么本文讲述的这些简单、有趣而实用的的 One Line HTTP Server 或许能让你大开眼界~
python -m SimpleHTTPServer 8000 -- Python 3.x: python -m http.server 8000
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()'
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start' -- Ruby 1.9.2+ ruby -run -ehttpd . -p8000
gem install adsf # install dependency adsf -p 8000
gem install sinatra # install dependency ruby -rsinatra -e'set :public_folder, "."; set :port, 8000'
cpan HTTP::Server::Brick # install dependency perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'
cpan Plack # install dependency plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000
cpan Mojolicious::Lite # install dependency perl -MMojolicious::Lite -MCwd -e 'app->static->paths->[0]=getcwd; app->start' daemon -l http://*:8000
npm install -g http-server # install dependency http-server -p 8000
npm install -g node-static # install dependency static -p 8000
php -S 127.0.0.1:8000 -- 需要 -t 指定 root dir 或者启动目录下创建 index.php:<?php phpinfo(); ?> 来测试效果
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"}]}]).'
busybox httpd -f -p 8000
webfsd -F -p 8000
C:\> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\MyWeb /port:8000
[1] Big list of http static server one-liners
https://gist.github.com/willurd/5720255
[2] 300行python代码的轻量级HTTPServer实现文件上传下载