ApacheにFastCGIでデプロイ前提
Apacheの設定<IfModule !mod_fcgid.c> LoadModule fcgid_module modules/mod_fcgid.so </IfModule> <Directory /var/www/my_app/public> Options All AllowOverride All </Director> フロントコントローラ/var/www/my_app/public/index.fcgiに設置する。 #!/usr/bin/perl use strict; use warnings; use lib qw( /var/www/my_app/lib ); use Mojo::Server::FastCGI; $ENV{MOJO_APP} = 'MyApp'; $ENV{BASE_URL} = '/myapp/'; Mojo::Server::FastCGI->new->run;
mod_rewriteでフロントコントローラにリクエストを集める/var/www/my_app/public/.htaccessに設置する。 AddHandler fcgid-script .fcgi RewriteEngine On RewriteBase /myapp RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.fcgi [QSA,L] アプリケーションクラスでのルーティング設定__PACKAGE__->attr( base_url => $ENV{BASE_URL} ); sub startup { my $self = shift; my $base = $self->base_url; my $r = $self->routes; $r->route("${base}index")->to(controller => 'top', action => 'index')->name('top'); # (注) $self->renderer->add_helper( url_for => sub { my $script_path = $self->base_url . $0; $script_path =~ s/\./\\./g; ( my $url = shift->url_for(@_) ) =~ s#$script_path##; return $url; } ); } 注
|
|