0

我将很快升级到Debian 6.0 "Squeeze"服务器上的 Linux,我想知道如何在许多专用于不同事物的端口上使用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 中不同)

4

2 回答 2

2

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

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

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

于 2010-10-01T05:04:59.330 回答
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()
于 2010-10-01T08:50:56.910 回答