eselskas
eselskas

Reputation: 817

Nginx config for Slim Framework API routes

I have been stuck with this for quite some time now. Basically, i have a routing file in my Slim Framework App which routes my API and then i can access the routes like so: "index.php/api/route". This works fine with apache or php -S. But now when i migrated to an nginx server with php5-fpm, i am facing issues with configuring the site properly. I can access index.php, but anything after is a 404. Checking the logs give me "no such file or folder" or "not a 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 tested with the commented out lines, to no success. Any ideas?

Upvotes: 3

Views: 9163

Answers (1)

eselskas
eselskas

Reputation: 817

Nevermind, i was just missing a try_files for the index.php path

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

Upvotes: 7

Related Questions