简体   繁体   English

Unix域套接字上的Apache到PSGI代理

[英]Apache-to-PSGI proxy over a Unix domain socket

We have many (isolated) installations of a PSGI app that run on the same machine and thus require their PSGI servers to run on unique ports. 我们在同一台计算机上运行了很多(单独的)PSGI应用程序,因此需要它们的PSGI服务器在唯一的端口上运行。 This is less than ideal from a resource/management perspective, but it also requires the (yet-unmeasured and possibly insignificant) "overhead" of TCP/IP when a Unix domain socket would seem to be more obvious choice when running on the same machine. 从资源/管理的角度来看,这不是理想的选择,但是当在同一台机器上运行Unix域套接字似乎是更明显的选择时,它还需要TCP / IP的(尚未测量且可能不重要的)“开销”。 。

Fortunately, the app works under Plack's HTTP interface (proxied from Apache via mod_proxy's "ProxyPass"), but unfortunately, it breaks under the FastCGI interface (see: https://stackoverflow.com/questions/14643165/can-psgi-apps-fork-under-plackhandlerfcgi ). 幸运的是,该应用程序可以在Plack的HTTP接口下运行(通过mod_proxy的“ ProxyPass”从Apache代理),但是不幸的是,它在FastCGI接口下无法正常工作(请参阅: https : //stackoverflow.com/questions/14643165/can-psgi-apps- fork-under-plackhandlerfcgi )。

Other than mod_fastcgi's FastCgiExternalServer (or patching mod_proxy with this untested, user-contributed patch: http://mail-archives.apache.org/mod_mbox/httpd-dev/201207.mbox/%3C20120731200351.GB11038@gmail.com%3E ), is there any way to proxy Apache connections over a Unix domain socket to a PSGI app? 除了mod_fastcgi的FastCgiExternalServer(或使用未经测试的,用户提供的补丁来修补mod_proxy: http ://mail-archives.apache.org/mod_mbox/httpd-dev/201207.mbox/%3C20120731200351.GB11038@gmail.com%3E) ,是否可以通过Unix域套接字将Apache连接代理到PSGI应用?

Proxying to a Unix domain socket should work with mod_proxy since Apache 2.4.7 and Starman . 从Apache 2.4.7和Starman开始,代理到Unix域套接字应该与mod_proxy一起使用。

Another approach is to run the different PSGI apps in a single process. 另一种方法是在单个过程中运行不同的PSGI应用程序。 I use something similar to the following wrapper app to achieve this: 我使用类似于以下包装器应用程序的方法来实现此目的:

use strict;
use warnings;

use lib qw(
    /path/to/app1
    /path/to/app2
    /path/to/app3
);

use Plack::Builder;
use Plack::Util;

sub load_psgi_in_dir {
    my ($dir, $psgi) = @_;
    my $app = Plack::Util::load_psgi("$dir/$psgi");
    return sub {
        chdir($dir);
        return $app->(@_);
    };
}

builder {
    mount 'http://app1.com/' => load_psgi_in_dir(
        '/path/to/app1',
        'app1.psgi',
    );
    mount 'http://app2.com/' => load_psgi_in_dir(
        '/path/to/app2',
        'app2.psgi',
    );
    mount 'http://app3.com/' => load_psgi_in_dir(
        '/path/to/app3',
        'app3.psgi',
    );
};

The only problem I had was that some apps used different versions of a local module with the same name. 我唯一的问题是某些应用程序使用了具有相同名称的本地模块的不同版本。 After fixing that everything worked fine. 修复后,一切正常。

A considerable benefit of this approach is that you can share workers across all your apps which reduces memory usage (or enables you to add more workers). 这种方法的显着优点是您可以在所有应用程序之间共享工作程序,从而减少了内存使用(或使您可以添加更多工作程序)。

There is mod_proxy_fdpass which allows Apache to proxy to domain sockets, although I haven't tried it. mod_proxy_fdpass ,它允许Apache代理到域套接字,尽管我还没有尝试过。

I was personally recommend using the standard each-app-on-a-port arrangement, unless you can measure the overhead to be worth doing something unconventional for. 我个人建议使用标准的每端口逐个应用程序安排,除非您可以衡量开销以值得做一些非常规的事情。

You also have the option of using one private-to-the-server IP address per app, and having them all run on port 80 on their private IPs. 您还可以选择为每个应用使用一个私有的服务器IP地址,并使它们全部在其私有IP的端口80上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM