Empty value to PATH_INFO in nginx returns junk value

后端 未结 1 1846
北海茫月
北海茫月 2021-01-24 21:47

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:

    fas         


        
相关标签:
1条回答
  • 2021-01-24 22:07

    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; 
    
    0 讨论(0)
提交回复
热议问题