【问题标题】:PHP HTTP server? Ports 80, 443-444, 1000-3000, 8000-9000. (No-Apache)PHP HTTP 服务器?端口 80、443-444、1000-3000、8000-9000。 (无阿帕奇)
【发布时间】:2010-10-01 04:53:07
【问题描述】:

我将很快升级到服务器上的 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 中不同)

【问题讨论】:

    标签: php python apache ports debian-based


    【解决方案1】:

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

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

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

    【讨论】:

    • 是否可以使用 bash 或 python 来实现?并且证书将是自签名并供个人使用,443 证书将转到我的主域。
    • 你的问题没有意义。 Bash 是一个命令外壳,不是端口转发器,也不是 Web 服务器。但是,您确实可以使用 bash 调用命令来配置两者。 Python 是一种语言,并且(如 PHP)通常作为 Web 浏览器内的环​​境运行。
    • 嗯,我可以使用 python 作为 http 服务器吗?
    • 您可以将 Python 作为 Web 服务器运行,是的。但是使用 Apache 有什么问题呢?
    【解决方案2】:

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

    【讨论】:

    • 这只是我需要的开始。
    猜你喜欢
    • 2017-02-17
    • 2010-11-12
    • 2010-11-15
    • 2021-09-13
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    相关资源
    最近更新 更多