views:

91

answers:

2

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)

A: 

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.

staticsan
Is it possible to do so with bash or python? And the certs would be self signed and for personal usage and the 443 certificate would go to my main domain.
JamesM
Your question doesn't make sense. Bash is a command shell, not a port-forwarder nor a web server. However, you can indeed use bash to call the commands to configure both. Python is a language, and (like PHP) usually run as an environment inside a web browser.
staticsan
humm could i use python as a http server to do this?
JamesM
You could run Python as a web server, yes. But what's wrong with using Apache?
staticsan
A: 

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()
JamesM
This is only a starter to what I need.
JamesM