Last active
June 14, 2018 10:41
-
-
Save AhnMo/ab8daaa2c4689a383f078ebcdcee6b1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import SimpleHTTPServer | |
| import SocketServer | |
| import logging | |
| import sys | |
| import os | |
| PORT = 3000 | |
| BASE = '..' | |
| class ParkServer(SocketServer.TCPServer, SocketServer.ThreadingMixIn): | |
| allow_reuse_address = True | |
| class ParkHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
| def log_message(self, format, *args): | |
| if 'X-NginX-Proxy' in self.headers and self.headers['X-NginX-Proxy'] == 'true': | |
| remote_ip = self.headers['X-Forwarded-For'] or self.headers['X-Real-IP'] | |
| else: | |
| remote_ip = self.address_string() | |
| sys.stderr.write("%s - - [%s] %s\n" % ( | |
| remote_ip, | |
| self.log_date_time_string(), | |
| format % args | |
| ) | |
| ) | |
| os.chdir(BASE) | |
| httpd = ParkServer(("", PORT), ParkHandler) | |
| try: | |
| httpd.serve_forever() | |
| except KeyboardInterrupt, e: | |
| pass | |
| print "Terminate server" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment