编辑了问题。我有这个简单的 Plack app.psgi
:
my $app = sub {
my $env = shift;
return [
200,
['Content-Type' => 'text/html'],
[ "<html><head><title>x</title></head><body><pre>Path info: $env->{PATH_INFO}</pre></body></html>"],
];
};
use Plack::Builder;
builder {
enable 'Debug';
$app;
};
用一个简单的plackup
运行它。
当从本地计算机访问: http://localhost:5000/some/path
时,它会打印: Path info: /some/path
,并得到了一个很好的工作 Plack 调试面板。
现在,我apache:80
配置如下:
ProxyPass /myapp/ http://127.0.0.1:5000/
ProxyPassReverse /myapp/ http://127.0.0.1:5000/
因此,所有请求的内容:http://SITE/myapp/
被代理到上述 Plack 应用程序。因此,当尝试通过以下方式访问它时
http://SITE/myapp/some/path
浏览器再次正确打印:
Path info: /some/path
但是"Plack::Middleware/Debug"不起作用,因为他将下一个URL发送到浏览器:
jquery.js -> /debug_toolbar/jquery.js
toolbar.min.js -> /debug_toolbar/toolbar.min.js
当然,它们不存在。(它们应该是/myapp/debug_toolbar/....
)
所以问题是:
- 我需要做什么 - 如何更改上面的app.psgi以获得一个工作的应用程序?
- 我需要
somewhat
更改带有前缀的所有传出 URL/myapp/
更新:我想您所需要的只是添加以下内容
enable "ReverseProxy"; ## Plack::Middleware::ReverseProxy
enable "ReverseProxyPath"; ## Plack::Middleware::ReverseProxyPath
更新:您可能还需要编辑您的 apache httpd conf 以将 nocanon 添加到 proxypass...
以下*是*原始**响应
它不是硬编码的,你自己看看(我不得不)
https://github.com/plack/Plack/wiki/How-to-detect-reverse-proxy-and-SSL-frontendhttp://p3rl.org/Plack::Middleware::ReverseProxyhttp://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and-urlmap.html
#!/usr/bin/perl --
#~ plack-debug-mounted.pl
#~ 2013-10-17-02:59:26
#~
## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*"
#!/usr/bin/perl --
use CGI();
use Data::Dump qw/ dd pp /;
use Path::Tiny qw/ path /;
use Plack::Builder;
use Plack::Runner;
my $selfsourceapp = sub {
return [
'200',
[ 'Content-Type' => 'text/plain', ],
[ path( __FILE__ )->slurp_raw ],
];
};
my $dumperapp = sub {
my $q = CGI->new( $_[0] );
return [
'200', [
'Content-Type' => 'text/html',
'Content-Length' => '2',
], [
$q->start_html( -title => 'dumpenv.psgi' ),
$q->h1( $_[0]->{SCRIPT_NAME} ),
$q->Dump, $q->end_html,
],
];
};
my $indexapp = sub {
return [
'200',
[ 'Content-Type' => 'text/html', ],
[
q{<doctype html>
<html lang="en-US" charset="UTF-8">
<title> Plack perlology </title>
<body>
<p> A Plack::Middleware::Debug free zone
<br> <a href="/"> this </a>
<br> <a href="/dumpenv"> dupenv </a>
<br> <a href="/selfsrc"> selfsrc </a>
<p> Get <c>Plack::Middleware::Debug</c> <b> ed </b>
<br> <a href="/debugged/"> /debugged/ this </a>
<br> <a href="/debugged/dumpenv"> /debugged/dupenv </a>
<br> <a href="/debugged/selfsrc"> /debugged/selfsrc </a>
<p> Come get some
<br> <a href="/debugged/debug_toolbar/toolbar.min.css">
/debugged/debug_toolbar/toolbar.min.css
</a>
<br> <a href="/debugged/debug_toolbar/toolbar.min.js">
/debugged/debug_toolbar/toolbar.min.js
</a>
<p> Cant get this
<br> <a href="/debug_toolbar/toolbar.min.css">
/debug_toolbar/toolbar.min.css
</a>
<br> <a href="/toolbar.min.css">
/toolbar.min.css
</a>
</body><!-- before this Plack::Middleware::Debug inserts, viewsource!! -->
}
],
];
};
my $finalapp = builder {
mount '/debugged' => builder {
enable 'Debug', panels => [
qw/
Timer
Response
Environment
Session
Parameters
/
];
mount "/dumpenv" => $dumperapp;
mount "/selfsrc" => $selfsourceapp;
mount "/" => $indexapp;
};
mount "/dumpenv" => $dumperapp;
mount "/selfsrc" => $selfsourceapp;
mount "/" => $indexapp;
};
my $runner = Plack::Runner->new;
$runner->parse_options( qw' --host 127.0.0.1 --port 80 ' );
$runner->run( $finalapp );