Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created December 27, 2012 07:58
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kazeburo/4386440 to your computer and use it in GitHub Desktop.
use Plack::App::CGIBin;
use Plack::App::PHPCGI;
use Plack::Builder;
use File::Zglob;
my $cgibin = Plack::App::CGIBin->new(
root => "/usr/local/nagios/sbin",
exec_cb => sub { my $file = shift; $file =~ m!\.cgi$! and -x $file },
)->to_app;
my $static = Plack::App::File->new(root => "/usr/local/nagios/share")->to_app;
my @php;
for my $php ( zglob("/usr/local/nagios/share/**/*.php") ) {
my $mount = $php;
$mount =~ s!^/usr/local/nagios/share!/nagios!;
my $app = Plack::App::PHPCGI->new(
script => $php,
php_cgi => '/usr/local/php/bin/php-cgi',
);
push @php, [$mount,$app];
}
builder {
enable 'ReverseProxy';
enable sub {
my $apps = shift;
sub {
my $env = shift;
return [302,[Location=>'http://'.$env->{HTTP_HOST}.'/nagios/'],['moved']] if $env->{PATH_INFO} eq '/';
$env->{REMOTE_USER} = 'nagios';
$env->{PATH_INFO} .= 'index.php'
if $env->{PATH_INFO} =~ m!^/nagios/([^\.]+/)*$!;
$apps->($env);
};
};
for my $php ( @php ) {
mount $php->[0], $php->[1];
}
mount '/nagios/cgi-bin' => $cgibin,
mount '/nagios' => $static,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment