[Moscow.pm] развертывание PSGI приложения используя mod_perl 2
TheAthlete
theathlet на yandex.ru
Сб Сен 7 04:06:26 PDT 2013
Здравстуйте!
Пытаюсь развернуть PSGI-приложение c помощью mod_perl 2, Plack в
.htaccess.
В документации Plack написано, что в httpd.conf нужно написать следующие
строки
<Location />
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/app.psgi
</Location>
Но если использовать .htaccess, то нужно писать следующим образом:
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/app.psgi
т.к. <Location> не поддерживается в .htaccess.
В результате error.log выдается ошибка:
Your request path is '/' and it doesn't match your Location(Match)
'/home/user/vhosts/test.org/'. This should be due to the configuration
error. See perldoc Plack::Handler::Apache2 for details.
Посмотрел в исходик Plack::Handler::Apache2, нашел такой код:
# The method for PH::Apache2::Registry to override.
sub fixup_path {
my ($class, $r, $env) = @_;
# $env->{PATH_INFO} is created from unparsed_uri so it is raw.
my $path_info = $env->{PATH_INFO} || '';
# Get argument of <Location> or <LocationMatch> directive
# This may be string or regexp and we can't know either.
my $location = $r->location;
# Let's *guess* if we're in a LocationMatch directive
if ($location eq '/') {
# <Location /> could be handled as a 'root' case where we make
# everything PATH_INFO and empty SCRIPT_NAME as in the PSGI spec
$env->{SCRIPT_NAME} = '';
} elsif ($path_info =~ s{^($location)/?}{/}) {
$env->{SCRIPT_NAME} = $1 || '';
} else {
# Apache's <Location> is matched but here is not.
# This is something wrong. We can only respect original.
$r->server->log_error(
"Your request path is '$path_info' and it doesn't match your
Location(Match) '$location'. " .
"This should be due to the configuration error. See perldoc
Plack::Handler::Apache2 for details."
);
}
$env->{PATH_INFO} = $path_info;
}
Т.е. здесь не обрабатывается вариант использования данного модуля в
.htaccess (т.к. <Location> запрещен). Подскажите пожайлуста, как можно
решить данную проблему. Я решил следующим образом: добавил переменную
is_htaccess yes и проверяю ее. Если она установлена, то $location
присваиваем '/':
# The method for PH::Apache2::Registry to override.
sub fixup_path {
my ($class, $r, $env) = @_;
# $env->{PATH_INFO} is created from unparsed_uri so it is raw.
my $path_info = $env->{PATH_INFO} || '';
# Get argument of <Location> or <LocationMatch> directive
# This may be string or regexp and we can't know either.
my $location = $r->location;
$location = '/' if $r->dir_config('is_htaccess') eq 'yes';
# Let's *guess* if we're in a LocationMatch directive
if ($location eq '/') {
# <Location /> could be handled as a 'root' case where we make
# everything PATH_INFO and empty SCRIPT_NAME as in the PSGI spec
$env->{SCRIPT_NAME} = '';
} elsif ($path_info =~ s{^($location)/?}{/}) {
$env->{SCRIPT_NAME} = $1 || '';
} else {
# Apache's <Location> is matched but here is not.
# This is something wrong. We can only respect original.
$r->server->log_error(
"Your request path is '$path_info' and it doesn't match your
Location(Match) '$location'. " .
"This should be due to the configuration error. See perldoc
Plack::Handler::Apache2 for details."
);
}
$env->{PATH_INFO} = $path_info;
}
Файл .htaccess
<Perl>
unshift @INC, '/path/to/custom/plack/lib';
</Perl>
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /home/user/vhosts/test.org/app.psgi
PerlSetVar is_htaccess yes
Данный код работает, какие еще есть варианты, замечания? Можно как-то
по-другому узнать, что это файл .htaccess?
Подробная информация о списке рассылки Moscow-pm