Posted by: Airtower | 2010-06-12

Instant minimal web server

Since quite some time I make sure to compile my system’s BusyBox with the included httpd to have a minimal web server available when I need it. A quick

$ busybox httpd -p 8080

is enough to offer the current directory via HTTP on port 8080. This post describes an alternative which has the advantage of being available on almost every Linux installation: Python comes with a built-in web server. Just go into the directory you want to use as the server’s root and run:

$ python -m SimpleHTTPServer 8080

If you don’t specify a port number, the server will use port 8000 (and fail if it can’t bind it). Directory listings are supported. In Python 3, the module is called http.server. Example:

$ python3 -m http.server 8113
Serving HTTP on 0.0.0.0 port 8113 ...
localhost - - [11/Jun/2010 19:53:26] "GET / HTTP/1.1" 200 -
localhost - - [11/Jun/2010 19:53:27] code 404, message File not found
localhost - - [11/Jun/2010 19:53:27] "GET /favicon.ico HTTP/1.1" 404 -
[some more transfers...]
^C
Keyboard interrupt received, exiting.

Quite useful when you just want to get some files from one computer to another, and the recipient needs only a browser (or any other HTTP client). However, BusyBox’s httpd is more configurable (just check busybox httpd --help), so I am going to keep it around.

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: