Search code examples
phppythonapacheportsdebian-based

PHP HTTP server? Ports 80, 443-444, 1000-3000, 8000-9000. (No-Apache)


I will upgrading to Linux Debian 6.0 "Squeeze" on the server soon and I want to know how I can use Python as a web-server on many ports dedicated for different things..

Ports            Directory           Description
80, 443          /var/www/sitegen/   Take all domains and generate a site from the SQL DB
444, 1000-3000   /var/www/manager/   Take 444 as a PHP server manager and the rest to be forwarded to serial hardware.
8000-9000        The VMs DIR         Forward the port to port 80 (or 443 by settings) on the VMs.

This Means that the port 443 could be used for many sites (powered by the same code just diffrent in the SQL DB)


Solution

  • In python:

    import os
    from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    
    class myHandler(BaseHTTPRequestHandler):
    
        def do_GET(self):
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write("This is working")
    
    def main():
        try:
            server = HTTPServer(("", 8080), myHandler)
            print "Sever is up.."
            server.serve_forever()
        except KeyboardInterrupt:
            print
            print "Bye, Bye!"
            server.socket.close()
    
    if __name__ == "__main__":
        main()