I\'m looking for a reliable way to configure Mojolicious running behind an Apache reverse proxy under /app, so that url_for(\'/foo\')
actually returns /ap
You need to set base path for each request url in before_dispatch hook
$app->hook(before_dispatch => sub {
my $c = shift;
$c->req->url->base->path('/app/');
});
Example:
use Mojolicious::Lite;
app->hook(before_dispatch => sub {
shift->req->url->base->path('/app/');
});
get '/' => sub {
my $c = shift;
$c->render(text => $c->url_for('test'));
};
get '/test/url' => sub { ... } => 'test';
app->start;
And result:
$ curl 127.0.0.1:3000
/app/test/url