Powered By Blogger

Oct 4, 2014

How to use SimpleHTTPServer

In this post it shows how you can setup a web server to serve content with minimal effort.

The SimpleHTTPServer module comes with Python and it is a simple HTTP server that
provides standard GET and HEAD request handlers. The main advantage is you don't need to install and configure anything. The only thing you need is to have Python installed in your machine.

You can use this to turn any directory in your system into your web server directory.

To start a HTTP server on port 8000 (which is the default port), simple type:

python -m SimpleHTTPServer [port]

This will now show the files and directories which are in the current working
directory.

You can also change the port to something else:

$ python -m SimpleHTTPServer 8080

In your terminal, cd into the directory you wish to have accessible via browsers and HTTP.
and then enter, 

$ python -m SimpleHTTPServer

After you hit enter, you should see the following message:

Serving HTTP on 0.0.0.0 port 8000 ...

Open your browser and put in any of the following addresses:

http://your_ip_address:8000
 
If you don't have an index.html file in the directory, then all files and directories will be listed.

As long as the HTTP server is running, the terminal will update as data are loaded from the Python web server. 

No comments:

Post a Comment