Я нахожу два варианта с корнем или псевдонимом.
С корнем:
server {
server_name domain.tld www.domain.tld;
root /var/www/project/public;
location /api {
index index.php;
root /var/www/project/api/public;
try_files $uri /api/index.php$is_args$args;
location ~ ^/api(/index\.php(/|$)) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param DOCUMENT_URI index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$1;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
С псевдонимом:
server {
server_name domain.tld www.domain.tld;
root /var/www/project/public;
location /api {
index index.php;
alias /var/www/project/api/public;
try_files $uri $uri/ /api/api/index.php$is_args$args;
location ~ ^/api/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param DOCUMENT_URI index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
Для понимания, как это должно бытьЯ использую
fastcgi_pass 127.0.0.1:9000;
и
#tcpdump -nAs 20000 -i lo tcp port 9000