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

2 Answers 2

2

Use

location ~ ^.+.php {

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

to match a .php in the uri split the parameters

1
  • That matches too broadly—on any character followed by "php". You need backslashes before literal periods.
    – dgatwood
    Mar 19, 2016 at 21:26
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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.