Score:0

Nginx + Laravel inside /api folder: File not found

gb flag

I have the following config for Angular (JS) app, where the laravel (PHP) API for the same app is inside the 'api' folder:

server {
    listen 80;
    server_name example.com www.example.com; 
    root /var/www/html/mydomain.com; #path to static directory
    index index.html index.htm index.php;
    charset utf-8;
    location / {
            try_files $uri $uri/ /index.php?$args;
        }

    location /api {
            alias /var/www/html/example.com/api/public;
            try_files $uri $uri/ @laravelapi;
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass   127.0.0.1:9072;  #set port for php-fpm to listen on
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                
        }
    }
location @laravelapi {
            rewrite /api/(.*)?$ /api/index.php?$is_args$args last;
    }
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
        deny all;
    }
}

the web (JS) works great, but all APi calls such as: http://www.example.com/api/public/pokemons fail with "File not found" message. Checking the error_log file of nginx:

2022/03/18 12:08:47 [error] 8028#8028: *26642 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 198.41.242.154, server: example.com, /127.0.0.1:9072", host: "www.example.com"

Not sure why there is an issue, I have other websites running on the same PHP FPM config and they work just fine.

Any idea what I'm missing?

djdomi avatar
za flag
i dont think that Pokémon is a business related issue. Are you looking for superuser.com?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.