Simple HTTP File Servers

2013-08-16

When you want to serve files over a network to web browsers, you can avoid the hassles of setting up a full-blown web server by using Python's SimpleHTTPServer:

$ python -m SimpleHTTPServer 8080

The command above shares the files located in the current directory over HTTP. You can access the files through a web browser using the URL http://host:8080 where host is the host name or IP address of the computer which executes the command.

While SimpleHTTPServer is able to serve directory trees, the following shell command by Razvan Tudorica serves the single file index.html with the help of the tool netcat:

$ while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done

In the comment section of Razvan's blog post, readers suggest further approaches.