Linux command
simplehttpserver 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Serve current directory
python3 -m http.server
Serve on a specific port
python3 -m http.server [8080]
Bind to localhost
python3 -m http.server --bind [127.0.0.1]
Serve a specific directory
python3 -m http.server --directory [path/to/dir]
Enable CGI
python3 -m http.server --cgi
Python 2 equivalent
python -m SimpleHTTPServer [8080]
说明
http.server (Python 3) and SimpleHTTPServer (Python 2) are Python standard library modules that launch a basic HTTP server for serving static files. They require no installation or configuration, making them ideal for quick file sharing, local development, and testing. In Python 2, the module is invoked as python -m SimpleHTTPServer, while Python 3 renamed it to python3 -m http.server. The server provides directory listings in a web browser and handles GET and HEAD requests. It binds to all interfaces on port 8000 by default, but the port and bind address can be customized.
参数
- -b, --bind _ADDRESS_
- Bind to address (default: all interfaces). Python 3 only.
- -d, --directory _DIR_
- Serve specified directory instead of current directory (Python 3.7+).
- --cgi
- Enable CGI script execution from /cgi-bin.
- --protocol _VERSION_
- HTTP protocol version (default: HTTP/1.0).
FAQ
What is the simplehttpserver command used for?
http.server (Python 3) and SimpleHTTPServer (Python 2) are Python standard library modules that launch a basic HTTP server for serving static files. They require no installation or configuration, making them ideal for quick file sharing, local development, and testing. In Python 2, the module is invoked as python -m SimpleHTTPServer, while Python 3 renamed it to python3 -m http.server. The server provides directory listings in a web browser and handles GET and HEAD requests. It binds to all interfaces on port 8000 by default, but the port and bind address can be customized.
How do I run a basic simplehttpserver example?
Run `python3 -m http.server` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -b, --bind _ADDRESS_ do in simplehttpserver?
Bind to address (default: all interfaces). Python 3 only.