PHP HTTP 服务器?端口 80、443-444、1000-3000、8000-9000。 (无阿帕奇)

发布于 2024-09-25 08:00:53 字数 571 浏览 6 评论 0原文

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

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 中有所不同)

I will upgrading to Linux Debian 6.0 "Squeeze" on the server soon and I want to know how I can use Python as a web-server on many ports dedicated for different things..

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.

This Means that the port 443 could be used for many sites (powered by the same code just diffrent in the SQL DB)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-10-02 08:00:53

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

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

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

This isn't a PHP question as the PHP interpreter doesn't directly listen on ports. On Linux, it will (usually) run inside Apache. Apache can be configured to listen to multiple ports, and even on a per-virtual host basis.

Also, be aware that the nature of HTTPS makes it impossible for multiple virtual hosts to use their own SSL certificate and still all listen on the same port. They will each need their own certificate and need to listen on their own port.

In addition, sending specific ports to virtual machines running on the box is nothing to do with the web server, let alone the execution environment. This is a mix of configuring the port forwarding inside the virtual network, coupled with local web server configuration in your virtual machines.

蓝戈者 2024-10-02 08:00:53

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

In 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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文