Static HTTP Web Server Using Python

Ever had the need to quickly spin up a temporary webserver so you can access it from the network?

You can do this with python as its installed by default and this method doesn’t even need any packages to be installed. Once you are in the folder that needs to be exposed, run the following.

Note that both the methods will expose the webserver at http://127.0.0.1:8000. If it needs to be accessed from another computer, don’t specify the bind param as it binds itself to all interfaces by default and access the webserver at http://<webserver IP>:8000

Python 3

python3 -m http.server 8000 --bind 127.0.0.1

Both port and bind address are optional. For more details, please refer the official docs for more details.

Python 2

python -m SimpleHTTPServer 8000

Python 2.x can only accept port as a parameter Bind address parameter is not available. Please refer the Python 2.x docs for more details

References