在我以前的问题中,我询问了一个多域解决方案,但这个问题太复杂了。
现在,简而言之:
是否可能以某种方式使用Starman (或任何其他纯perl服务器)设置基于名称的虚拟主机,比如使用<VirtualHost ...>指令?或者我需要使用Apache来获得这种功能吗?
有什么想法吗?
发布于 2011-05-18 15:00:38
中间件已经在Plack::建筑工人中使用Plack::App::URLMap完成了。吊舱上写着:
用主机名映射URL也是可能的,在这种情况下,URL映射就像虚拟主机一样工作。
语法在第三次挂载中:
builder {
mount "/foo" => builder {
enable "Plack::Middleware::Foo";
$app;
};
mount "/bar" => $app2;
mount "http://example.com/" => builder { $app3 };
};发布于 2011-10-17 15:51:14
这里的例子是:一些站点的一个模块(App)。
您的lib/YourApp.pm应为:
package YourApp;
use strict;
use warnings;
use Dancer ':syntax';
setting apphandler => 'PSGI';
Dancer::App->set_running_app('YourApp');
# This and other routes ...
get '/' => sub {
# Static and template files will be from different directories are
# based by host http header
template 'index';
};
1;你的bin/app.psgi应该是:
#!/usr/bin/perl
use strict;
use warnings;
use Dancer;
# The next line can miss but need for quickly loading in L<Starman> server
use YourApp;
use Plack::Builder;
# Please notice that here no need ports in url
# So for http://app1.foo.com:3000/ will work
# http://app1.foo.com/
my $hosts = {
'http://app1.foo.com/' => '/appdir/1',
'http://app2.foo.com/' => '/appdir/2'
};
builder {
my $last;
foreach my $host (keys %$hosts) {
$last = mount $host => sub {
my $env = shift;
local $ENV{DANCER_APPDIR} = $hosts->{$host};
load_app "YourApp";
Dancer::App->set_running_app('YourApp');
setting appdir => $hosts->{$host};
Dancer::Config->load;
my $request = Dancer::Request->new( env => $env );
Dancer->dance($request);
};
}
$last;
};您可以尝试使用这个my模块--我认为它比构建器和映射更容易进行虚拟托管:
https://stackoverflow.com/questions/6045399
复制相似问题