Simple command line HTTP server

Try SimpleHTTPServer:

python -m SimpleHTTPServer
# or the Python 3 equivalent
python3 -m http.server

It should will serve whatever's in the CWD (e.g. index.html) at http://0.0.0.0:8000.


There is a Big list of http static server one-liners:

To get on this list, a solution must:

  1. serve static files using your current directory (or a specified directory) as the server root
  2. be able to be run with a single, one line command (dependencies are fine if they're a one-time thing)
  3. serve basic file types (html, css, js, images) with proper mime types, require no configuration (from files or otherwise) beyond the command itself (no framework-specific servers, etc)
  4. must run, or have a mode where it can run, in the foreground (i.e. no daemons)

For example:

  • Twisted (Python)

    twistd -n web -p 8000 --path . 
    
  • 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"}]}]).'
    
  • Plack (Perl)

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

    webfsd -F -p 8000
    
  • Ruby 1.9.2+

    ruby -run -ehttpd . -p8000
    

Use node.js , fast and lightweight.

Or

just use simple nc netcat command to start a quick webserver on a port and serve the content of a file including the server response headers.

Reference from Wikipedia:

http://en.wikipedia.org/wiki/Netcat#Setting_up_a_one-shot_webserver_on_port_8080_to_present_the_content_of_a_file

{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat some.file; } | nc -l -p 8080
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <some.file)\r\n\r\n"; cat some.file; } | nc -l -p 8080