问题
I created a simple API using mojolicious
, but I've just migrated from Apache to Nginx
and cannot figure out how to handle url correctly
Here is my Server Block configuration file
server {
listen 80;
listen [::]:80;
root /var/www/example.com/public_html;
index index.pl index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
gzip off;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:8090;
fastcgi_param SCRIPT_FILENAME /var/www/example/public_html/$fastcgi_script_name;
}
}
It is handled by Mojolicious
but I get following result.
Method: GET
URL:
Base URL: http://example.com/clients/
As you can see base url is captured ,but URL is empty.
My pattern is
Pattern Methods Name
/clients GET clients
What is wrong ? How can I handle requests correctly ?
回答1:
I have faced with the same problem. I have found the following solution.
app->hook(before_dispatch => sub {
my $c = shift;
$c->tx->req->url->path->{'path'} = @{$c->tx->req->env}{'REQUEST_URI'};
});
app->start;
It is a quick and dirty solution, but it works.
Hope this helps.
来源:https://stackoverflow.com/questions/43290656/mojolicious-is-not-capturing-url-only-base-url