多语言PSGI-Web部署 [英] Multilingual PSGI-web deployment

查看:138
本文介绍了多语言PSGI-Web部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划使用PSGI / Plack开发一个Web应用程序。 (可能与
Dancer达成协议,但尚未决定)。

I plan develop one web application with PSGI/Plack. (probaly with Dancer, but not decided yet).

应用程序应为utf8,多语言(使用Locale :: Maketext)和(ofc)将包含给定语言的一些静态页面。我的想法是将其部署到不同的语言域中,例如 en.example.com de.example.com 等。应用程序本身很简单,通常只会用本地化的文本和一些其他(轻型)功能填充模板。

The applicatiion should be utf8, multilingual (with Locale::Maketext) and (ofc) will contain some statical pages in the given language. My idea is deploy it in different language domains like en.example.com, de.example.com etc. The application itself is simple, mostly will only fill templates with localized texts and some other (light) functionality.

什么是部署一个的最佳解决方案>在一个物理机上应用基于多个语言的子域?

What is the best solution to deploying one application for mutiple language-based sub-domains in one physical machine?

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

My current research ended with this solution: need to use Apache and its name based virtual servers for every language subdomain.

<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>

问题:


  • 最佳解决方案是什么?

  • 与Starman或其他pure-perl服务器一起存在任何解决方案吗?如果是,怎么办?反向代理?

  • 纯perl解决方案会更好(更快)吗?

  • 我应该考虑其他解决方案吗? (fcgi,nginx等...)

  • What is the best solution?
  • Exists any solution with Starman or other pure-perl server? If yes, how? Reverse proxy?
  • Will be the pure perl solution better (faster)?
  • should i consider some other solution? (fcgi, nginx etc...)

任何可能对发展本身产生影响的想法/事物 >?

推荐答案

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

Use Plack::App::URLMap to setup a virtualhost in Starman (or whatever PSGI compatible web servers):

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;

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

in generate_app you can setup/configure whatever needed to return a new PSGI app. If you want to share the same $app instance but want to dynamically change the behavior, you can do so by writing PSGI middleware, like:

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

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

Note that you probably want to put Starman behind proxy, in which case you should configure the frontend (nginx/Apache/lighttpd etc.) to forward the Host: header as it is to the backend.

这篇关于多语言PSGI-Web部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆