Slim Framework API 路由的 Nginx 配置

Nginx config for Slim Framework API routes

我已经坚持了很长一段时间了。基本上,我的 Slim Framework 应用程序中有一个路由文件,它路由我的 API,然后我可以像这样访问路由:"index.php/api/route"。这适用于 apache 或 php -S。但是现在当我迁移到带有 php5-fpm 的 nginx 服务器时,我面临着正确配置站点的问题。我可以访问 index.php,但之后的任何内容都是 404。检查日志给我 "no such file or folder" 或 "not a directory"。这是我当前的配置:

server {
  listen 80;
  listen [::]:80 default_server ipv6only=on;
  server_name www.site.com;
  root /var/www/site;
  index index.php;

  error_log /var/log/nginx/site.error.log;
  access_log /var/log/nginx/site.access.log;

  location ~ \.php$ {
    fastcgi_connect_timeout 5s;
    fastcgi_read_timeout 10s;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_index index.php;
    include fastcgi_params;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

我用注释掉的行进行了测试,但没有成功。有什么想法吗?

没关系,我只是缺少 index.php 路径的 try_files

location / {
    try_files $uri $uri/ /index.php?$query_string;
}