Instant Python HTTP server

The quick and dirty way of starting an instant web server is by means of Python‘s simple HTTP request handler.

The following command will start listening to HTTP requests on port <port> (if <port> is blank a default value of 8000 is assumed) and will be serving files from the current directory:

$ python -m SimpleHTTPServer <port>

On the host’s console the access log will be displayed (example):

Serving HTTP on 0.0.0.0 port 4444 ...
<source address> - - [16/May/2013 12:12:17] "GET / HTTP/1.1" 200 -
<source address> - - [16/May/2013 12:12:17] "GET /favicon.ico HTTP/1.1" 404 -
<source address> - - [16/May/2013 12:12:19] "GET /example_file.txt HTTP/1.1" 200 -
...

To stop the server, according to the above-mentioned quick and dirty approach, issuing CTRL+C is fine (a traceback will be printed by the Python interpreter, that’s not something to worry about).

Source: http://osxdaily.com/2010/05/07/create-an-instant-web-server-via-terminal-command-line/

Leave a comment