PHP HTTP服务器?端口80,443-444,1000-3000,8000-9000。 (否的Apache)

时间:2010-10-01 04:53:08

标签: php python apache ports debian-based

我很快就会在服务器上升级到Linux Debian 6.0 "Squeeze" ,我想知道如何在许多专用端口上使用 Python 作为Web服务器对于不同的事情..

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中的不同代码提供支持)

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:0)

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