1

When the PATH_INFO set by nginx is empty string, I get some junk character while accessing it from PHP.

This is how I set the PATH_INFO in nginx:

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param  PATH_INFO  $fastcgi_path_info;

It works fine if the path info has some non-empty value. I even reinstalled nginx, but it didn't help. nginx version is 1.0.5 (I'm using Ubuntu 11.10, if at all it matters).

viky
  • 542
  • 1
  • 7
  • 19
  • Please give an example of a path and the value it generates. – DaveRandom Nov 25 '11 at 08:46
  • 1
    When the url is something like `http://localhost/myapp/index.php`, the PATH_INFO is supposed to be empty, but returns junk. When it's something like `http://localhost/myapp/index.php/testing`, PATH_INFO is "/testing". – viky Nov 25 '11 at 09:12
  • When you say it returns junk, can you give an example of this junk? – DaveRandom Nov 25 '11 at 09:30
  • It is some random character; sometimes an alphabet, sometimes a special character like |, sometimes some unreadable character like � , – viky Nov 25 '11 at 09:42

1 Answers1

0

I got the same thing a view days ago .. therefore I changed the regexp to look like this:

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

And added a view other lines to make it work most likely to Apache.

Here's the whole diff I've done to the file fastcgi_params

@@ -3,13 +3,22 @@
 fastcgi_param  CONTENT_TYPE        $content_type;
 fastcgi_param  CONTENT_LENGTH      $content_length;

-fastcgi_param  SCRIPT_FILENAME     $request_filename;
+#fastcgi_param SCRIPT_FILENAME     $request_filename;
 fastcgi_param  SCRIPT_NAME     $fastcgi_script_name;
 fastcgi_param  REQUEST_URI     $request_uri;
 fastcgi_param  DOCUMENT_URI        $document_uri;
 fastcgi_param  DOCUMENT_ROOT       $document_root;
 fastcgi_param  SERVER_PROTOCOL     $server_protocol;

+fastcgi_split_path_info ^(.+\.php)(/.*)$;
+fastcgi_param  PATH_INFO       $fastcgi_path_info;
+set        $path_translated    "";
+if ($fastcgi_path_info) {
+   set     $path_translated    $document_root$fastcgi_path_info;
+}
+fastcgi_param  PATH_TRANSLATED     $path_translated;
+fastcgi_param  SCRIPT_FILENAME     $document_root$fastcgi_script_name;
+
 fastcgi_param  GATEWAY_INTERFACE   CGI/1.1;
 fastcgi_param  SERVER_SOFTWARE     nginx/$nginx_version;

Using this configuration you always have the PATH_INFO variable instead of how it's done in f.e. Apache.

Some of the scripts I used just checked like this what (of course) does not work with my configuration:

if (!isset($_SERVER['PATH_INFO']) { doSomething() }

I adviced the main-developer to change it to this:

if (!isset($_SERVER['PATH_INFO'] || empty($_SERVER['PATH_INFO']) { doSomething() }

If you want to take a look im my full-server-configuration, just take a look in this github-repository: https://github.com/SimonSimCity/webserver-configuration/

Edit: I found a blog with a slightly different solution. I have not tested it yet, but it seems to be a bit smaller ;) http://www.jzxue.com/fuwuqi/http-iis-apache/201108/19-8538.html

set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /var/html/$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info; 
SimonSimCity
  • 6,415
  • 3
  • 39
  • 52