2010-10-01 103 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