<p>也许这能奏效。将以下内容保存到文件中:</p>
<p><strong>服务时间</strong></p>
<pre><code>#!/usr/bin/env python
import SimpleHTTPServer
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
if __name__ == '__main__':
SimpleHTTPServer.test(HandlerClass=MyHTTPRequestHandler)
</code></pre>
<p>然后用</p>
<pre><code>python serveit.py 8000
</code></pre>
<p>服务端口8000上的当前目录。这是完全被拉<a href="https://gist.github.com/dustingetz/5348582" rel="noreferrer">from this gist</a>,似乎工作伟大!</p>
<p>注意:如果您只是想运行一个本地web服务器来提供静态内容,那么您可能会对一个<a href="https://github.com/indexzero/http-server" rel="noreferrer">precanned node solution to do this => http-server</a>感兴趣,我一直在使用它,它看起来工作得很好。</p>
<p>如果你在mac上,如果你以根用户身份运行,你可以在端口80或443上运行!例如</p>
<p><code>sudo python serveit.py 80</code></p>
<p>应该允许您运行它并在浏览器中访问它<code>http://localhost</code></p>