Can not run on Nginx

Hi, guys:
I am a newer to using slim framework 4. I use centos7 and nginx and php-fpm 7.3.
Here are my index.php

<?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require 'autoload.php'; $app->get('/', function (Request $request, Response $response, $args) { $response->getBody()->write("Hello world!");** return $response;** }); $app->run(); ?>

and return

Notice : Undefined variable: app in /usr/share/nginx/html/slim4/vendor/index.php on line 9

Fatal error : Uncaught Error: Call to a member function get() on null in /usr/share/nginx/html/slim4/vendor/index.php:9 Stack trace: #0 {main} thrown in /usr/share/nginx/html/slim4/vendor/index.php on line 9

but when I use
php -S localhost:9500 index.php
it is ok, what’s wrong with me ? thanks
I want use http://x.x.x.x:9500/slim4

here my nginx.conf
location /slim4 {
alias /usr/share/nginx/html/slim4/public;
index index.php;

    location ~ \.php$ {
      # fastcgi_pass;
      # try_files $uri=404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      # fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                                                       # fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/slim4/public$fastcgi_script_name;
      fastcgi_param SCRIPT_NAME $fastcgi_script_name;
      include fastcgi_params;

The vendor/ directory is reserved for the composer autoloader.

The index.php file should be stored in the public/ directory

This will not work: require 'autoload.php'; It should be something like:

require_once __DIR__ . '/../vendor/autoload.php';

Please read the manual: