"Ad-hoc webserver" for static files on UNIX/MacOSX? "Ad-hoc webserver" for static files on UNIX/MacOSX? unix unix

"Ad-hoc webserver" for static files on UNIX/MacOSX?


If you have python installed:

$ python -m SimpleHTTPServerServing HTTP on 0.0.0.0 port 8000 ...


$ python -m SimpleHTTPServer [port]

will start a webserver in the current directory serving whatever files are found there.

In a few cases this won't work well, for example the server is single-threaded (so no simultaneous downloads) and doesn't handle byte-range requests (clients expecting Range: support often fail badly).


Python3 can serve the current directory via HTTP using http.server:

$ python3 -m http.server

Where

  • python3 the current version of python
  • -m stands for module
  • http the http package
  • http.server the server module (of the http package)

Per default, http.server listens on port 8000, but you can specify another like this:

$ python3 -m http.server 8080