Slim PHP Framework在Nginx的子目录中路由

我有一个网站example.com工作文件在/ var / www / html和一个router.php处理path和文件路由(以一种效率不高的方式,但一切工作正常)。

我试图使用Slim框架在/ var / www / html / api / v1的子目录中创buildapi,该子目录具有我的index.php应用程序文件和其他api相关文件。

API在本地主机工作正常,但是我努力configuration网站+ API与Nginx一起。

常规网页工作正常

example.com/page1 => var/www/html/router.php example.com/page2 => var/www/html/router.php 

但是,当我尝试达到我的api(Slim index.php应用程序),它返回404。

 example.com/api/v1/users => var/www/html/api/v1/index.php example.com/api/v1/products => var/www/html/api/v1/index.php 

这是我的网站可用的configuration:

 server { listen 80; server_name example.com; root /var/www/html; index index.php index.html; location / { #try_files $uri $uri/ /router.php?$query_string; rewrite ^/([a-zA-Z0-9_-]+)$ /router.php?pid=$1; rewrite ^/([a-zA-Z0-9_-]+)/$ /router.php?pid=$1; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /router.php?pid=$1&pid2=$2; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /router.php?pid=$1&pid2=$2; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /router.php?pid=$1&pid2=$2&pid3=$3; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /router.php?pid=$1&pid2=$2&pid3=$3; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /router.php?pid=$1&pid2=$2&pid3=$3&pid4=$4; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /router.php?pid=$1&pid2=$2&pid3=$3&pid4=$4; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /router.php?pid=$1&pid2=$2&pid3=$3&pid4=$4&pid5=$5; rewrite ^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /router.php?pid=$1&pid2=$2&pid3=$3&pid4=$4&pid5=$5; } location /api/ { root /var/www/html/api/v1/; try_files $uri $uri/ /index.php?$query_string =404; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_pass unix:/run/php/php7.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

在我的nginx错误日志中,它不显示任何错误。 任何人有任何线索或提示?

谢谢你的帮助!