6. July 2014

Simple HTTP server in Python 3.x on specific port

One very cool feature of Python 3.x is instant web server. Type the following command on command line:

python -m http.server

The Python will start a simple web server serving content from the working directory at URL: http://localhost:8000.

It’s also possible to specify the port to open, simply add the port number as the next parameter:

python -m http.server 8080

The web server by default operates on all network interfaces. It’s possible to restrict which interface to bind by the following command:

python -m http.server -b 192.168.1.10 8080

This web server will be accessible only from http://192.168.1.10:8080

A similar command is also available for old Python 2.x:

python -m SimpleHTTPServer