0

I got a Laravel installation in /srv/http/v1. The index.php is within /srv/http/v1/public as usual with laravel. It is nginx running with php-fpm.

It should be mapped to this second level subdir app.example.com/api/v1

It can be called by app.excampe.com/api/v1 without any problem. But e.g. app.example.com/api/v1/anything returns me a 404 from nginx. The route exists inside laravel and if not, the 404 should be the laravel one.

My current nginx config for the location is

location /api/v1 {
    include /etc/nginx/php_fastcgi_location.conf;
    alias /srv/http/v1/public;
    index index.php;
    try_files $uri $uri/ /api/v1/index.php?$query_string;
}

I guess there is something wrong with try_files, but i got no clue :-( So i would welcome helpful hints.

0

I have found a solution myself:

location /api/v1 {
    include /etc/nginx/php_fastcgi_location.conf;
    alias /srv/http/v1/public;
    index index.php;

    try_files $uri $uri/ @apiv1;
}

location @apiv1 {
    rewrite /api/v1/(.*)$ /api/v1/index.php?/$1 last;
}

Although i have found this by trial and error, i would be happy if someone could explain the reason for the problem and the solution.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.