Created
December 27, 2012 07:58
-
-
Save kazeburo/4386440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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