Python 3和http.server用法

时间:2016-03-25 17:25:12

标签: python http

我想知道我是否有index.html并且在Windows CMD中运行python -m http.server 80而在index.html的目录中它会在我的IP上启动服务器(假设我打开了端口80)然后人们可以只需连接到我的IP并查看index.html中的内容?

2 个答案:

答案 0 :(得分:1)

如果

  1. 您的路由器是TCP 80的端口转发
  2. 服务器正在侦听0.0.0.0
  3. 没有防火墙妨碍
  4. 然后它将公开访问。要使其仅在本地主机上可用,您应该在127.0.0.1

    上托管
    httpd = ServerClass(("127.0.0.1", 80), HandlerClass)
    

    编辑:另一个答案发布了这个好的链接,直到发布后才看到:Is it possible to run python SimpleHTTPServer on localhost only?

答案 1 :(得分:0)

人们应该能够毫无问题地连接到您的公共IP。如果您只想从localhost提供访问权限,那将会更复杂一些:

Is it possible to run python SimpleHTTPServer on localhost only?