Problem with fastcgi_split_path_info on ubuntu precise

zakaria nginx-forum at nginx.us
Sun May 5 11:04:21 UTC 2013


Francis Daly Wrote:
-------------------------------------------------------
> Hi there,
> > And the result with cgi.fix_pathinfo = 1 (the default)

> As an aside -- I find that "cgi.fix_pathinfo = 1" removes the "do what
> I say" part of php configuration, so I run without it. But I don't
> believe that that's relevant here.

cgi.fix_pathinfo=0 gives incorrect PHP_SELF.

> >   'PATH_INFO' => '',
> >   'TEST_PATH_INFO' => '',

> Thanks for testing that. It suggests to me that the problem is on the
> nginx side: $fastcgi_path_info is empty at the time the fastcgi_param
> directive takes effect.

> > So here's my request to you all:
> > 1. Is my config correct? I'm sure it is.

> It doesn't do what you want it to do, which is a strong hint in one
> direction ;-)

> But I don't see any reason why that should be the case.

> I do see two possible config changes you could make, each of which
> seems
> enough to get things working as you want.

> Either: remove the "try_files" line; or replace the "fastcgi_param
> PATH_INFO" line with two lines:

> fastcgi_param PATH_INFO $mypath;
> set $mypath $fastcgi_path_info;

> These seem to work because $fastcgi_path_info does have the correct
> value in the "rewrite" phase, but loses it after the "try files"
> phase. I don't understand why that is the case. That upsets me.

Thank you for confirm it.
Its nginx bug #321 http://trac.nginx.org/nginx/ticket/321

For the benefit of the man from the future (http://xkcd.com/979/),
here's my final configuration:
------------------------------------------------------------
        location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                # Save the $fastcgi_path_info before try_files clear it
                set $path_info $fastcgi_path_info;
                fastcgi_param PATH_INFO $path_info;
                try_files $fastcgi_script_name =404;

                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
------------------------------------------------------------

with /test.php:
------------------------------------------------------------
<pre><?php var_export($_SERVER) ?></pre>
------------------------------------------------------------

and php.ini cgi.fix_pathinfo = 1 (the default).

When given request http://lemp.test/test.php/foo/bar.php?v=1 would produce:
------------------------------------------------------------
array (
  'USER' => 'www-data',
  'HOME' => '/var/www',
  'FCGI_ROLE' => 'RESPONDER',
  'PATH_INFO' => '/foo/bar.php',
  'QUERY_STRING' => 'v=1',
  'REQUEST_METHOD' => 'GET',
  'CONTENT_TYPE' => '',
  'CONTENT_LENGTH' => '',
  'SCRIPT_FILENAME' => '/var/www/test.php',
  'SCRIPT_NAME' => '/test.php',
  'REQUEST_URI' => '/test.php/foo/bar.php?v=1',
  'DOCUMENT_URI' => '/test.php',
  'DOCUMENT_ROOT' => '/var/www',
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'GATEWAY_INTERFACE' => 'CGI/1.1',
  'SERVER_SOFTWARE' => 'nginx/1.1.19',
  'REMOTE_ADDR' => '192.168.56.1',
  'REMOTE_PORT' => '46281',
  'SERVER_ADDR' => '192.168.56.3',
  'SERVER_PORT' => '80',
  'SERVER_NAME' => 'localhost',
  'HTTPS' => '',
  'REDIRECT_STATUS' => '200',
  'HTTP_HOST' => 'lemp.test',
  'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0)
Gecko/20100101 Firefox/20.0',
  'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
  'HTTP_CONNECTION' => 'keep-alive',
  'PHP_SELF' => '/test.php/foo/bar.php',
  'REQUEST_TIME' => 1367750028,
)
------------------------------------------------------------

> > 3. Is there something wrong on the latest ubuntu precise?
> >    Or is it just my imagination that I have it working before? :)

> Were you perhaps previously using an older nginx version where it
> worked as expected?

> Or is the "try_files" line a new addition since Friday?

Most probably, I forget to reload the server after I changed the config
(combining try_files with fastcgi_split_path_info), 
try it in the browser thinking all is well.

Thank you all for helping this nginx newbie.

> 	f
> -- 
> Francis Daly        francis at daoine.org

-- Zakaria

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,238825,238860#msg-238860



More information about the nginx mailing list