0

Nginx returns a 404 when I query for an URL with a "path info" appended after the script name, e.g. http://example.com/index.php/hello.

Here is my config:

server {
    listen  80;
    root    @PROJECT_ROOT@/;
    index   index.php index.html;

    location ~ \.php$ {
        fastcgi_pass    unix:@PHP_FPM_SOCK@;
        include fastcgi_params;
        fastcgi_read_timeout 300s;
    }
}

I don't get why \.php$ doesn't match that URL, and I've tried searching for similar problems but can't find anything useful.

2
  • The pattern \.php$ is forcing nginx to match only URLs ending with .php. Why dont you a look on how popular frameworks arrange this setup like Symfony2? symfony.com/doc/current/cookbook/configuration/… Commented Oct 15, 2014 at 5:59
  • @softius ah good point! Thanks Commented Oct 15, 2014 at 22:07

2 Answers 2

2

Use

location ~ ^.+.php {

fastcgi_split_path_info ^(.+?.php)(/.*)$;

to match a .php in the uri split the parameters

Sign up to request clarification or add additional context in comments.

1 Comment

That matches too broadly—on any character followed by "php". You need backslashes before literal periods.
1

This works for me:

location ~ \.php {
    # Split the path appropriately
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;

    # Work around annoying nginx "feature" (https://trac.nginx.org/nginx/ticket/321)
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

    # Make sure the script exists.
    try_files $fastcgi_script_name =404;

    # Configure everything else.  This part may be different for you.
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.