{"id":623,"date":"2021-04-26T14:40:52","date_gmt":"2021-04-26T06:40:52","guid":{"rendered":"http:\/\/www.xxhjkl.me\/?p=623"},"modified":"2021-04-26T14:40:53","modified_gmt":"2021-04-26T06:40:53","slug":"%e5%a4%9a%e7%ba%bf%e7%a8%8b%e7%89%88simplehttpserver","status":"publish","type":"post","link":"https:\/\/www.xxhjkl.me\/?p=623","title":{"rendered":"\u591a\u7ebf\u7a0b\u7248SimpleHTTPServer"},"content":{"rendered":"\n<p>\u6700\u8fd1\u6709\u4e2a\u5c0f\u9879\u76ee\u9700\u8981\u5728\u5185\u7f51\u8d77\u4e00\u4e2ahttp\u670d\u52a1\uff0c\u7ed9\u5185\u7f51\u7684\u5176\u4ed6\u673a\u5668\u5206\u53d1\u5185\u5bb9\u3002\u4e34\u65f6\u7528\u4e00\u4e0b\u7684\uff0c\u800c\u4e14\u5185\u7f51\u641enginx\uff0c\u6216\u8005caddy\u4e4b\u7c7b\u7684\u90fd\u6bd4\u8f83\u9ebb\u70e6\uff0ccaddy\u597d\u50cf\u81ea\u52a8\u8981\u53bb\u7533\u8bf7\u8bc1\u4e66\uff0c\u600e\u4e48\u90fd\u641e\u4e0d\u597d\u3002\u6211\u53ea\u9700\u8981\u5355\u7eaf\u7684\u8d77\u4e2ahttp\u670d\u52a1\u8ba9\u5185\u7f51\u5176\u4ed6\u673a\u5668\u6765wget\u5c31\u597d\u4e86\u3002\u67e5\u4e86\u4e00\u4e0bpython\u81ea\u5e26\u7684SimpleHTTPServer\u5c31\u633a\u65b9\u4fbf\u7684\u4e00\u53e5\u8bdd\u5c31\u80fd\u8d77\u670d\u52a1\u3002\u8bd5\u4e86\u4e00\u4e0b\u786e\u5b9e\u6bd4\u8f83\u597d\u7528\uff0c\u4f46\u662f\u6709\u4e2a\u6bd4\u8f83\u660e\u663e\u7684\u7f3a\u70b9\u5c31\u662f\u5355\u7ebf\u7a0b\u7684\uff0c\u5f53\u5185\u7f51\u6709\u591a\u4e2a\u673a\u5668\u9700\u8981\u83b7\u53d6\u5185\u5bb9\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u4e00\u4e2a\u4e2a\u6392\u961f\u6765\u4e0b\u8f7d\uff0c\u8fd9\u6837\u6548\u7387\u6bd4\u8f83\u4f4e\u3002\u67e5\u4e86\u4e00\u4e0b\u7f51\u7edc\u4e0a\u4e5f\u6709\u522b\u4eba\u6709\u641e\u8fc7\u591a\u7ebf\u7a0b\uff0c\u6c47\u96c6\u4e86\u4e00\u4e0b\u8d44\u6e90\u3002\u653e\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import socket\r\nimport SocketServer\r\nimport BaseHTTPServer\r\nfrom SimpleHTTPServer import SimpleHTTPRequestHandler\r\n\r\n\r\nclass ForkingHTTPServer(SocketServer.ForkingTCPServer):\r\n\r\n    allow_reuse_address = 1\r\n\r\n    def server_bind(self):\r\n        \"\"\"Override server_bind to store the server name.\"\"\"\r\n        SocketServer.TCPServer.server_bind(self)\r\n        host, port = self.socket.getsockname()&#91;:2]\r\n        self.server_name = socket.getfqdn(host)\r\n        self.server_port = port\r\n\r\n\r\ndef test(HandlerClass=SimpleHTTPRequestHandler,\r\n    ServerClass=ForkingHTTPServer):\r\n    BaseHTTPServer.test(HandlerClass, ServerClass)\r\n\r\n\r\nif __name__ == '__main__':\r\n    test()<\/code><\/pre>\n\n\n\n<p>\u628a\u4e0a\u9762\u7684\u4ee3\u7801\u547d\u540d\u6210MultithreadHTTPServer.py<\/p>\n\n\n\n<p>\u5982\u679c\u4e0d\u9700\u8981\u5168\u5c40\u8dd1\uff0c\u5047\u8bbe\u4e0a\u9762\u8fd9\u4e2a\u6587\u4ef6\u653e\u5728\/root\u4e0b\u5c31\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m \/root\/MultithreadHTTPServer 9000<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u5c31\u4f1a\u5728ip:9000\u8d77\u4e00\u4e2ahttp\u670d\u52a1\u76f4\u63a5\u8bbf\u95eehttp:\/\/ip:9000 \u5c31\u597d\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u60f3\u8981\u548c\u539f\u751f\u7684SimpleHTTPServer\u4e00\u6837\u4e0d\u7528\u5e26\u76ee\u5f55\u5c31\u80fd\u8dd1\u7684\u8bdd\u3002\u9700\u8981\u628aMultithreadHTTPServer.py\u653e\u5230pip\u7684\u5b89\u88c5\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u5148\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u627epip\u5b89\u88c5\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -c \"import SimpleHTTPServer;help(SimpleHTTPServer)\"<\/code><\/pre>\n\n\n\n<p>\u4f1a\u663e\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME\r\n    SimpleHTTPServer - Simple HTTP Server.\r\n\r\nFILE\r\n    \/usr\/lib64\/python2.7\/SimpleHTTPServer.py\r\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2aFILE\u5c31\u662f\u76ee\u5f55\u4e86\uff0c\u6211\u8fd9\u8fb9\u662f\/usr\/lib64\/python2.7\/<\/p>\n\n\n\n<p>\u6240\u4ee5\u628aMultithreadHTTPServer.py\u4e22\u8fdb\u53bb\uff0c\u4e4b\u540e\u8fd0\u884c\u5c31\u4e0d\u9700\u8981\u5e26\u4e0a\u76ee\u5f55\u4e86\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m MultithreadHTTPServer 9000<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u8bd5\u4e86\u4e00\u4e0b\u591a\u4e2aip\u53ef\u4ee5\u540c\u65f6\u6765\u62d6\u6587\u4ef6\u4e86\uff0c\u4e0d\u9519\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6709\u4e2a\u5c0f\u9879\u76ee\u9700\u8981\u5728\u5185\u7f51\u8d77\u4e00\u4e2ahttp\u670d\u52a1\uff0c\u7ed9\u5185\u7f51\u7684\u5176\u4ed6\u673a\u5668\u5206\u53d1\u5185\u5bb9\u3002\u4e34\u65f6\u7528\u4e00\u4e0b\u7684\uff0c\u800c\u4e14\u5185\u7f51\u641enginx\uff0c\u6216\u8005caddy\u4e4b\u7c7b\u7684\u90fd\u6bd4\u8f83\u9ebb\u70e6\uff0ccaddy\u597d\u50cf\u81ea\u52a8\u8981\u53bb\u7533\u8bf7\u8bc1\u4e66\uff0c\u600e\u4e48\u90fd\u641e\u4e0d\u597d\u3002\u6211\u53ea\u9700\u8981\u5355\u7eaf\u7684\u8d77\u4e2ahttp\u670d\u52a1\u8ba9\u5185\u7f51\u5176\u4ed6\u673a\u5668\u6765wget\u5c31 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/posts\/623"}],"collection":[{"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=623"}],"version-history":[{"count":1,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":624,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions\/624"}],"wp:attachment":[{"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xxhjkl.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}