Apache-to-PSGI proxy through a Unix domain socket

We have many (isolated) PSGI application installations that run on the same computer and therefore require their PSGI servers to run on unique ports. This is less than ideal in terms of resources / management, but it also requires (yet immeasurable and possibly insignificant) TCP / IP overheads when a Unix domain socket seems to be a more obvious choice when running on the same machine.

Fortunately, the application runs under the Plack HTTP interface (proxy from Apache via mod_proxy "ProxyPass"), but, unfortunately, it breaks under the FastCGI interface (see https://stackoverflow.com/questions/14643165/can-psgi-apps -fork-under-plackhandlerfcgi ).

Besides mod_fastcgi FastCgiExternalServer (or mod_proxy fixes with this unverified user fix: http://mail-archives.apache.org/mod_mbox/httpd-dev/201207.mbox/% 3C20120731200351.GB11038@gmail.com% 3E ), is there a way Apache proxy connections through a Unix domain socket to a PSGI application?

0
source share
2 answers

Proxying to a Unix domain name should work with mod_proxy with Apache 2.4.7 and Starman .

Another approach is to run various PSGI applications in one process. To do this, I use something similar to the following wrapper application:

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',
    );
};

, , , . , .

, , ( ).

+3

mod_proxy_fdpass, Apache , .

---, , - .

IP- , 80 IP-.

+2

Source: https://habr.com/ru/post/1542754/


All Articles