了解的mod_proxy和Apache 2编写彗星服务器 [英] Understanding mod_proxy and Apache 2 for writing a comet-server

查看:159
本文介绍了了解的mod_proxy和Apache 2编写彗星服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我试图实现一个简单的HTTP服务器某种彗星 -technique (长轮询的XHR请求)。由于的JavaScript 是非常严格的跨域请求我有几个问题:

I currently try to implement a simple HTTP-server for some kind of comet-technique (long polling XHR-requests). As JavaScript is very strict about crossdomain requests I have a few questions:


  1. 我的理解而服务的要求,所以写了剧本作为通常网站会遮挡了Apache,当有一个请求所有工人担任任何Apache工人被阻止。 - >不工作

  2. 我想出了这个想法写一个自己的简单的HTTP服务器只为服务这个长轮询请求。此服务器不应该堵,每个工人可以处理在同一时间很多要求。正如我的网站还包含内容/图片等,并在我的服务器不需要服务器的内容我就开始了他的不同端口上,然后80现在的问题是,我无法将的JavaScript 我的Apache和不同的端口上运行我的彗星的服务器,因为一些跨域限制的交付。 - >不工作

  3. 然后,我想出了一个主意,用的mod_proxy 我的服务器映射一个新的子域。我真的不能够弄清楚如何的mod_proxy 的作品,但我能想象,我知道有作为我的第一种方法相同​​的效果?

  1. As I understood any apache worker is blocked while serving a request, so writing the "script" as a usual website would block the apache, when all workers having a request to serve. --> Does not work!
  2. I came up with the idea writing a own simple HTTP server only for serving this long polling requests. This server should not be blocking, so each worker could handle many request at the same time. As my site also contains content / images etc and my server does not need to server content I started him on a different port then 80. The problem now is that I can't interact between my JavaScript delivered by my apache and my comet-server running on a different port, because of some crossdomain restrictions. --> Does not work!
  3. Then I came up with the idea to use mod_proxy to map my server on a new subdomain. I really don't could figure out how mod_proxy works but I could imagine that I know have the same effect as on my first approach?

什么是创建这类组合的这种经典的网站和这些长轮询的XHR请求的最佳方式?我需要我自己来实现我的服务器上的内容交付?

What would be the best way to create these kind of combination this kind of classic website and these long-polling XHR-requests? Do I need to implement content delivery on my server at my own?

推荐答案

这是一个困难的问题。即使你过去你正在运行到安全问题,你最终不得不举行开放目前正在研究网页每一个客户端的TCP连接。您将不能创建一个线程来处理每个连接,您将无法从一个单独的线程所有连接选择。已经这样做过,我可以告诉你,这并不容易。你可能想看看的libevent ,其中的 memcached的使用了类似的结束。

This is a difficult problem. Even if you get past the security issues you're running into, you'll end up having to hold a TCP connection open for every client currently looking at a web page. You won't be able to create a thread to handle each connection, and you won't be able to "select" on all the connections from a single thread. Having done this before, I can tell you it's not easy. You may want to look into libevent, which memcached uses to a similar end.

在一定程度上你也许可以逃脱设定长期超时并允许Apache有工人,其中大部分将闲置的大部分时间的一个巨大的数字。仔细选择和Apache的工人模块的配置将延伸这数千个并发用户,我相信。在某一点,但是,它也不会扩大了。

Up to a point you can probably get away with setting long timeouts and allowing Apache to have a huge number of workers, most of which will be idle most of the time. Careful choice and configuration of the Apache worker module will stretch this to thousands of concurrent users, I believe. At some point, however, it will not scale up any more.

我不知道你在做什么的基础设施的样子,但我们有一个名为F5s网络机柜负载平衡箱。这些present单个外部域,但重定向流量根据它们的响应时间的多个内部服务器,在请求头,等等饼干。它们可以被配置为在虚拟域内发送请求为某个路径到特定的服务器。因此,你可以有映射到一个特定的服务器来处理这些彗星请求example.com/xhr/foo请求。不幸的是,这不是一个软件解决方案,但相当昂贵的硬件解决方案。

I don't know what you're infrastructure looks like, but we have load balancing boxes in the network racks called F5s. These present a single external domain, but redirect the traffic to multiple internal servers based on their response times, cookies in the request headers, etc.. They can be configured to send requests for a certain path within the virtual domain to a specific server. Thus you could have example.com/xhr/foo requests mapped to a specific server to handle these comet requests. Unfortunately, this is not a software solution, but a rather expensive hardware solution.

无论如何,你可能需要某种形式的负载平衡系统(也许你已经有一个),或许它可以被配置来处理这种情况比Apache更可以。

Anyway, you may need some kind of load-balancing system (or maybe you have one already), and perhaps it can be configured to handle this situation better than Apache can.

我有一个问题,几年前,我使用的是客户端 - 服务器系统与专有二进制协议能够访问端口80上我们的服务器想让客户,因为他们一直有与使用的系统自定义的端口上的防火墙问题。我需要的是将生活在端口80和指挥交通到Apache或取决于从什么客户端通过附带的前几个字节的应用程序服务器的代理。我找了一个解决方案,并没有发现任何合适。我考虑写一个Apache模块,用于委托等的插件,但最终还是以自己的自定义内容感应代理服务推出。也就是说,我认为,这就是你想要做什么,最坏的情况。

I had a problem years ago where I wanted customers using a client-server system with a proprietary binary protocol to be able to access our servers on port 80 because they were continuously having problems with firewalls on the custom port that the system used. What I needed was a proxy that would live on port 80 and direct the traffic to either Apache or the app server depending on the first few bytes of what came across from the client. I looked for a solution and found nothing that fit. I considered writing an Apache module, a plugin for DeleGate, etc., but eventually rolled by own custom content-sensing proxy service. That, I think, is the worst-case scenario for what you're trying to do.

这篇关于了解的mod_proxy和Apache 2编写彗星服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆