Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

一行Python命令搭建HTTP服务 #170

Open Qingquan-Li opened 3 years ago

Qingquan-Li commented 3 years ago

参考:


一、局域网内访问静态网页

如果你只需要一个简单的 Web Server ,场景例如:在局域网内使用手机测试访问电脑上的HTML静态网页。 此时,无需下载并配置 Nginx 或 Apache 或 ISS 这些复杂的 HTTP 服务程序。 安装 Python3 后,只需要一行命令就可以完成一个简单的内建 HTTP 服务器:

$ python -m http.server 8000  # 默认使用8000端口,也可以使用其他端口

http.server访问静态网页

此时,在局域网内的其他设备上的浏览器,输入 192.168.31.57:8000 (注意这里请使用你自己的 IP 和端口)即可访问到 ~/code/cxff 目录下的 index.html 网页(配合”花生壳等内网穿透工具“还可以实现公网访问):

访问静态网页screenshot



二、局域网内文件共享

http.server文件共享

文件共享screenshot