Multilingual PSGI Network Deployment

I plan to develop one web application using PSGI / Plack. (probably with the Dancer, but not yet decided).

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

What is the best solution for deploying one for multi-language subdomains on the same physical machine?

My current research ended up with this solution: I need to use Apache and its name-based virtual servers for each 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> 

Questions:

  • What is the best solution?
  • Is there any solution with Starman or another clean server? If so, how? Reverse Proxy?
  • Would a better perl solution be better (faster)?
  • Should I consider a different solution? (fcgi, nginx, etc.)

Any other ideas / things that might affect the development itself?

+7
source share
2 answers

Use Plack :: App :: URLMap to set up a virtual host in Starman (or any other web server that supports PSGI):

 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; 

in generate_app you can configure / configure everything you need to return a new PSGI application. If you want to share the same instance of $ app, but want to dynamically change the behavior, you can do this by writing PSGI middleware, for example:

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

Note that you probably want to install Starman as a proxy server, in which case you should configure the interface (nginx / Apache / lighttpd, etc.) to forward the Host: header, as well as for the backend.

+8
source

I did not think that there is a "better" way, there are just a lot of different ways, and each has its pros and cons.

Configuring Apache, like you, is possible, and I don’t understand why this should be bad. Another way is to “connect” each application to the path. This is described further: http://suryahunter.com/wiki/hunter/perl_ironman/mount_multiple_apps_with_plack

If you use PSGI / Plack at all, you can use any web server, as well as Starman or other Perl web servers. Which one you use is up to you. Use the one where you think it has the best performance, or the one you knew best.

Also think that when you start your server, you probably want to start your application automatically, and Apache, Nginx, LightTPD, ... already have startup scripts. If you also want to host other sites, then it is probably best to use one of these web servers.

I prefer FastCGI to run your application. With FastCGI, your application runs independently of your web server, and can also work with other user rights, and not with mod_perl, where all applications run under the same name as the Apache user. It also gives you the advantage that you can restart the application without restarting the full web server (Apache).

Well, through this independent, you probably need more RAM to run the same number of applications, because you run your applications several times instead of using the sharing that Apache / mod_perl gives you.

In the end, it depends on your needs for what is best.

+3
source

All Articles