apache 通过我的笔记本电脑公共IP地址提供HTTP服务- Python

pkln4tw6  于 2023-06-06  发布在  Apache
关注(0)|答案(1)|浏览(146)

我正在本地测试一个功能,我想使用自己的笔记本电脑,而不是使用EC2示例:

python3 -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

如果我做curl http://localhost:8000它将工作和网页被提取.但是如果我执行curl http://<my-ip-address>:8000,我得到:

<html><head><title>504 Gateway Timeout</title></head>
<body><h1>Gateway Timeout</h1>
<p>Server error - server <my-ip-address> is unreachable at this moment.<br><br>Please retry the request or contact your administrator.<br></p>
</body></html>

我怎样才能使我的IP地址通过分配给膝上型计算机的公共IP地址在浏览器中提供服务?

ruarlubt

ruarlubt1#

你可以使用模块http.server和绑定地址(0.0.0.0或你的本地地址),如下所示:

python3 -m http.server --bind 0.0.0.0

在您的例子中,似乎已经有东西在监听地址:8080,因为504是HTTP状态,您可以尝试在另一个端口上运行它,确保它可用(netstat -an)。

python3 -m http.server --bind 0.0.0.0 8888

相关问题