Ubuntu 使用 Python 启动 HTTP 服务
1, 启动服务
对于 Python 3,运行以下命令: python3 -m http.server 8000 默认端口为 8000,可根据需要更改端口号。
2, 指定目录
如果需要共享特定目录,可以使用 --directory 参数:
python3 -m http.server --directory /path/to/directory 8000
3, 使用低端口(如80)
如果需要使用低于1024的端口(如80),需要使用 sudo:
sudo python3 -m http.server --directory /path/to/directory 80
验证结果
打开浏览器,访问 http://localhost:8000 或 http://<服务器IP>:8000,即可查看共享目录内容。
