多语言PSGI-web部署

jm6*_*666 7 perl plack dancer psgi

我计划用PSGI/Plack开发一个Web应用程序.(与舞者有关,但尚未决定).

应用程序应该是utf8,多语言(使用Locale :: Maketext)和(ofc)将包含给定语言的一些静态页面.我的想法是将它部署在不同的语言域中en.example.com,de.example.com等等.应用程序本身很简单,大多数只会填充带有本地化文本和其他(轻量级)功能的模板.

在一台物理计算机中为多个基于语言的子域部署一个应用程序的最佳解决方案是什么?

我目前的研究以此解决方案结束:需要为每个语言子域使用Apache及其基于名称的虚拟服务器.

<VirtualHost en.example.com>
    ServerName en.example.com
    DocumentRoot /path/to/site/en/files
    <Location />
        SetHandler perl-script
        PerlResponseHandler Plack::Handler::Apache2
        PerlSetVar psgi_app /path/to/site/en/en.psgi
    </Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

问题:

  • 什么是最好的解决方案?
  • 使用Starman或其他纯perl服务器存在任何解决方案?如果有,怎么样?反向代理?
  • 纯粹的perl解决方案会更好(更快)吗?
  • 我应该考虑其他解决方案吗?(fcgi,nginx等...)

什么其他的想法/事物会对开发本身产生什么影响?

miy*_*awa 8

使用Plack :: App :: URLMap在Starman(或任何兼容PSGI的Web服务器)中设置虚拟主机:

use Plack::App::URLMap;
my $en_app = generate_app('en');
my $ru_app = generate_app('ru');

my $app = Plack::App::URLMap->new;
$app->map("http://en.example.com/" => $en_app);
$app->map("http://ru.example.com/" => $ru_app);
$app->to_app;
Run Code Online (Sandbox Code Playgroud)

在generate_app你可以设置/配置任何需要回到一个新的应用程序PSGI.如果您想共享相同的$ app实例但想要动态更改行为,可以通过编写PSGI中间件来实现,例如:

my $app = sub { MyApp->run(@_) };
my $en_app = sub {
   my $env = shift;
   $env->{'myapp.language'} = 'en';
   $app->($env);
};
my $ru_app = sub { ... }; # same
Run Code Online (Sandbox Code Playgroud)

请注意,您可能希望将Starman置于代理之后,在这种情况下,您应该配置前端(nginx/Apache/lighttpd等)以将Host:标头转发到后端.