2010-10-01 104 views
0

我很快就会升级到Linux Debian 6.0 "Squeeze"在服务器上,我想知道我怎么可以使用Python的作为上专用于不同的事情很多端口的Web服务器..PHP HTTP服务器?端口80,443-444,1000-3000,8000-9000。 (无阿帕奇)

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. 

这意味着端口443可以用于许多站点(由相同的代码支持,只是在SQL DB中有所不同)

回答

0

在蟒蛇:

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

这只是我需要的开始。 – 2010-10-01 08:51:53

2

这不是PHP问题,因为PHP解释器不会直接在端口上侦听。在Linux上,它将(通常)在Apache中运行。 Apache可以配置为侦听多个端口,甚至可以在每个虚拟主机的基础上侦听。

另外,请注意,HTTPS的本质使得多个虚拟主机无法使用自己的SSL证书,并且仍然都在相同的端口上侦听。他们每个人都需要自己的证书,并需要在自己的端口上收听。

此外,将特定端口发送到在该服务器上运行的虚拟机与Web服务器无关,更不用说执行环境了。这是在虚拟网络内配置端口转发的组合,以及虚拟机中的本地Web服务器配置。

+0

是否有可能使用bash或Python这样做呢?证书将会自行签名并用于个人使用,并且443证书将进入我的主域。 – 2010-10-01 05:29:36

+0

你的问题没有意义。 Bash是一个命令shell,不是端口转发器,也不是Web服务器。但是,您确实可以使用bash调用这些命令来配置两者。 Python是一种语言,并且(如PHP)通常作为Web浏览器内的环​​境运行。 – staticsan 2010-10-01 05:33:36

+0

humm我可以使用python作为http服务器来执行此操作吗? – 2010-10-01 05:59:35