'Slim3 API deployment issues on Nginx

I am a newbie in both nginx and slim, however I am trying to deploy a simple project on my VPS.

The entry point of my slim app is /root/my-project/server/public/index.php, and the project runs OK locally with php built-in server (php -S localhost:8080).

Remotely however, whenever I try to access my-domain.com/api I receive a 404. no errors are logged by nginx.

here is my nginx configuration:

server {
  listen 80;
  server_name www.my-domain.com my-domain.com;
  return 301 https://www.my-domain.com$request_uri;
}

server {
  listen 443 ssl http2;
  ssl_certificate path/to/my/certificate;
  ssl_certificate_key path/to/my/certificate/key;

  set $root_path /root/my-project;
  server_name www.my-domain.com my-domain.com;

# proxy to nuxt renderer.
  location / {
        proxy_pass http://localhost:3000;
  }

# entry point for API server
  location /api {
        root $root_path/server/public;
        index index.php;
        try_files $uri index.php$is_args$args;
  }

# copied from slim3 deployment doc
# https://www.slimframework.com/docs/v3/start/web-servers.html
  location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
  }
}

I am not sure what the last block, which I got from slim documentation, does.

  1. if I change the 404 value of try_files with another value, I would get that new code when visiting my-domain/api

  2. what is fastcgi_pass and why is it forwarding to port:9000?

but MOSTLY

  1. why my index.php slim entry point is never called?

I thank you in advance for any suggestions.

p.s just for additional info, I can start the slim app with php built-in server and it works, so I know that the project itself works in my remote environment. I need to understand how to run it via nginx.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source