Question

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)

Was it helpful?

Solution 2

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()

OTHER TIPS

This isn't a PHP question as the PHP interpreter doesn't directly listen on ports. On Linux, it will (usually) run inside Apache. Apache can be configured to listen to multiple ports, and even on a per-virtual host basis.

Also, be aware that the nature of HTTPS makes it impossible for multiple virtual hosts to use their own SSL certificate and still all listen on the same port. They will each need their own certificate and need to listen on their own port.

In addition, sending specific ports to virtual machines running on the box is nothing to do with the web server, let alone the execution environment. This is a mix of configuring the port forwarding inside the virtual network, coupled with local web server configuration in your virtual machines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top