simplehttpserver
Serve files over HTTP in a directory
TLDR
Start the HTTP server serving the current directory with verbose output (listen on all interfaces and port 8000 by default)
Start the HTTP server with basic authentication serving a specific path over port 80 on all interfaces
Start the HTTP server, enabling HTTPS using a self-signed certificate with custom SAN on all interfaces
Start the HTTP server with custom response headers and upload capability
Start the HTTP server with customizable rules in YAML (see documentation for DSL)
SYNOPSIS
To invoke the server, navigate to the directory you wish to serve files from.
Python 3:
python -m http.server [port] [--bind ADDRESS]
Python 2 (Deprecated):
python -m SimpleHTTPServer [port]
PARAMETERS
[port]
An optional integer specifying the TCP port the server will listen on. Defaults to 8000 if not provided. Choose a port above 1024 to avoid requiring root privileges.
--bind ADDRESS
(Python 3 only) An optional IP address or hostname to bind the server to. Use '0.0.0.0' to bind to all available network interfaces, allowing access from other devices on the network. Use '127.0.0.1' or 'localhost' for local access only.
(Implicit Directory)
The server serves files from the current working directory where the command is executed. To serve a different directory, first use the cd command to navigate into that directory before running the server command.
DESCRIPTION
The simplehttpserver, typically invoked as python -m http.server in Python 3 (or python -m SimpleHTTPServer in Python 2), provides a minimalistic HTTP web server. It is designed for quickly serving static files from the current directory or a specified path, making it ideal for local development, testing web content, or temporary file sharing within a local network.
Unlike robust production web servers like Apache or Nginx, simplehttpserver requires no complex configuration, starting instantly with a single command. It defaults to port 8000 but can be configured to use any available port. While incredibly convenient for quick tasks, it lacks essential security features, performance optimizations, and advanced functionalities required for public-facing or high-traffic applications. Its simplicity is its strength, offering an immediate solution for basic web serving needs.
CAVEATS
Not Production Ready: This server is for development and testing only. It lacks security features (like HTTPS, authentication, access control), robustness, and performance necessary for public-facing or high-traffic production environments.
Security Vulnerabilities: It serves all files in the current directory and its subdirectories without authentication or fine-grained access control. Do not use it in untrusted networks or with sensitive data.
Single-Threaded: It handles one request at a time, making it unsuitable for concurrent connections or heavy loads.
Python Dependency: Requires a Python interpreter to be installed on the system.
SERVING A SPECIFIC DIRECTORY
To serve files from a directory other than the current one, first use the cd command to change into that directory before executing python -m http.server. The server will then serve content from that new working directory.
ACCESSING THE SERVER
Once started, the server is typically accessible via your web browser. If bound to localhost, use http://localhost:8000 (or your chosen port). If bound to '0.0.0.0', you can access it from other devices on your local network using your machine's IP address (e.g., http://192.168.1.100:8000). Files will be listed as a directory index unless an index.html (or index.htm) file is present in the served directory.
STOPPING THE SERVER
To terminate the server, simply press Ctrl+C in the terminal window where it is running. This sends an interrupt signal to the Python process, causing it to shut down gracefully.
HISTORY
The functionality originated in Python 2 as the SimpleHTTPServer module, providing a basic, unconfigured HTTP server within Python's standard library. With the transition to Python 3, it was refactored and renamed to the http.server module, retaining its core simplicity and purpose. Its development focused on offering a quick, built-in solution for local web serving and file sharing without external dependencies, becoming a popular tool for developers and users needing immediate HTTP access to local files.