Nginx configuration for Slim Framework API routes

I've been stuck with this for quite a while. Basically, I have a routing file in my Slim Framework app that routes my API, and then I can access routes like this: "index.php / api / route". This works great with apache or php -S. But now that I have switched to nginx server with php5-fpm I am facing problems setting up the site correctly. I can access index.php but everything is after 404. Checking the logs gives me "no such file or folder" or "no directory". Here's my current config:

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;
  }
}

      

I've tested with commented lines, no success. Any ideas?

+3


source to share


1 answer


Nevermind, I just missed the try_files for the index.php path



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

      

+6


source







All Articles