Nginx fastcgi rewrite: primary script unknown

fastcginginx

I have following nginx configuration:

  location / {
      try_files $uri $uri/ index.html =404;

      if (!-e $request_filename) {
        rewrite ^/(.+)$ index.php?url=$1 last;
      }
  }


 location ~ .php$ {
    # protection from known vulnerability
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }

(fastcgi_params are defaults from Debian package)

it works for request /, however when the request is rewritten the main file is not found:

request is /contact which should be rewritten to /index.php?url=contact

 *104 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: localhost, request: "GET /contact HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost:8080"

I'm unable to get from logs what is actuall fastcgi trying to load, which path?

Best Answer

Note that index.php and /index.php are different URIs. You've forgotten slashes in your rewrites.