python快速搭建WebServer

#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
import os

PORT = 7777
WEBDIR = "/www/web/xxx_com/"

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def translate_path(self, path):
        os.chdir(WEBDIR)
        return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self,path)

try:
    httpd = SocketServer.TCPServer(("", PORT), Handler)
    print "dir %s serving at port %s"%(repr(WEBDIR), PORT)
    httpd.serve_forever()
except:pass

 

posted @ 2014-09-04 14:11  CHN.VMAX  阅读(310)  评论(0编辑  收藏  举报