扭曲+姜戈 +反向代理

发布于 2024-09-27 20:55:03 字数 1375 浏览 1 评论 0原文

我正在为我的网站部署twisted 作为网络服务器。我正在研究反向代理的可能性。

我现在将以下代码连接到我的 django 反应堆。我正在使用 comet,并且我意识到我绝对必须使用端口 80,因此我正在研究反向代理的可能性。在此站点上,我找到了以下示例:

# Django setup
sys.path.append("shoout_web")
os.environ['DJANGO_SETTINGS_MODULE'] = 'shoout_web.settings'

def wrapper_WSGIRootWrapper():
    # Build the wrapper first
    generic = WSGIHandler()
    def HandlerWrapper(environ, start_response):
        environ['engine'] = engine
        return generic(environ, start_response)

    # Thread and Allowing Ctrl-C to get you out cleanly:
    pool = threadpool.ThreadPool()
    pool.start()
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
    return wsgi.WSGIResource(reactor, pool, HandlerWrapper)
WSGIRoot = wrapper_WSGIRootWrapper()

# Reverse Proxy
class Simple(Resource):
    isLeaf = False

    def getChild(self, name, request):
        if name == "orbited":
            print "orbited"
            return proxy.ReverseProxyResource('localhost', 12345, "/"+name)
        else: 
            return WSGIRoot.getChildWithDefault(name, request)

# Attaching proxy + django 
log_dir = './.log'
if not os.path.exists(log_dir):
    os.makedirs(log_dir)
reactor.listenTCP(DJANGO_PORT, server.Site(Simple(), logPath=os.path.join(log_dir, '.django.log')))

我的麻烦是我真的不知道在第二个代码部分的 else 部分中填写什么。我查看了twisted-src上的text_proxy,但没有实质性的例子。有什么帮助吗?

I am deploying twisted as a web server for my site. I am looking into possibilities of reverse proxying.

I have the following code right now hooked up to my reactor for django. I am using comet, and I realize that I absolutely must use port 80 hence I am looking into possibilities of reverse proxying. On this site, I found the following example:

# Django setup
sys.path.append("shoout_web")
os.environ['DJANGO_SETTINGS_MODULE'] = 'shoout_web.settings'

def wrapper_WSGIRootWrapper():
    # Build the wrapper first
    generic = WSGIHandler()
    def HandlerWrapper(environ, start_response):
        environ['engine'] = engine
        return generic(environ, start_response)

    # Thread and Allowing Ctrl-C to get you out cleanly:
    pool = threadpool.ThreadPool()
    pool.start()
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
    return wsgi.WSGIResource(reactor, pool, HandlerWrapper)
WSGIRoot = wrapper_WSGIRootWrapper()

# Reverse Proxy
class Simple(Resource):
    isLeaf = False

    def getChild(self, name, request):
        if name == "orbited":
            print "orbited"
            return proxy.ReverseProxyResource('localhost', 12345, "/"+name)
        else: 
            return WSGIRoot.getChildWithDefault(name, request)

# Attaching proxy + django 
log_dir = './.log'
if not os.path.exists(log_dir):
    os.makedirs(log_dir)
reactor.listenTCP(DJANGO_PORT, server.Site(Simple(), logPath=os.path.join(log_dir, '.django.log')))

My trouble is I don't really know what to fill in in the else part of that second code part. I looked at text_proxy on twisted-src and there weren't substantial examples for this. Any help?

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

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

发布评论

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

评论(1

芸娘子的小脾气 2024-10-04 20:55:03

我不清楚你为什么要使用反向代理。我认为您试图出于错误的原因使用正确的工具。

反向代理很有用,因为您可以让像 nginx 这样的轻量级服务器以很少的内存开销处理数千个 http keep-alive 连接。相比之下,反向代理和真实 Web 服务器(在您的情况下是扭曲的)之间的连接较少且短暂,因此您可以处理更高的负载。请注意,如果您使用长期的彗星连接,则这里没有任何好处,因为您需要在持续时间内在两台服务器中打开连接。

您似乎想使用它来简单地使端口 12345 上的服务器在端口 80 上可用。这不是反向代理的用途。为什么不一开始就绑定80端口呢?

It is not clear to me why you want to use a reverse-proxy. I think you're trying to use the right tool for the wrong reasons.

Reverse proxy is useful because you can have a lightweight server like nginx handle thousands of http keep-alive connections with very little memory overhead. The connections between the reverse proxy and the real web server (twisted in your case) are fewer and short-lived by comparison, thus you can handle higher loads. Note that if you're using long-lived comet connections, there's no benefit here, because you need the connection open in both servers for the duration.

You seem to be wanting to use it to simply make the server on port 12345 available on port 80. This is not what a reverse-proxy is for. Why not just bind port 80 in the first place?

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