Opened 7 years ago

Closed 7 years ago

#509 closed defect (duplicate)

fastcgi_split_path_info Unsetting $fastcgi_path_info with Try_Files

Reported by: Mark Johnson Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.4.x
Keywords: fastcgi_path_info, fastcgi_split_path_info Cc:
uname -a: Linux NGINX-TEST-01 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux , Linux NGINX-TEST-02 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
nginx -V: nginx/1.4.1 (Ubuntu) , nginx/1.2.1

Description

When using a try_files inside a location block that will be using PHP-FPM the "fastcgi_split_path_info" method does NOT properly save the $fastcgi_path_info variable. With the try_files directive removed, the $fastcgi_path_info is set properly.

	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;

		# Define the results as fastcgi parameters for quick 
		# verification/debug via <?php print_$(SERVER); ?>
		fastcgi_param FASTCGI_SCRIPT_NAME	$fastcgi_script_name;
		fastcgi_param FASTCGI_PATH_INFO		$fastcgi_path_info;

		# FASTCGI_PATH_INFO reports blank when using try_files.
		try_files $fastcgi_script_name =404;

		# Alternatively, using an "evil-if" will result in the variables being set correctly.
		#if (!-f $document_root/$fastcgi_script_name) {
		#	return 404;
		#}

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

TO REPRODUCE

  1. Include the above location block in the default site (making changes where appropriate)
  1. Update/create the index.php as follows at the default server root on a clean Nginx install.
    <?php
    echo '<pre>';
    print_r($_SERVER);
    echo '</pre>';
    ?>
    
  1. Restart nginx.
  1. Navigate to:
    /index.php/foo/bar.php?param=1
    
  1. Expected Results Using try_files
    Array
    (
    	[FASTCGI_SCRIPT_NAME] => /index.php
    	[FASTCGI_PATH_INFO] => /foo/bar.php
    )
    
  1. Actual Results Using try_files
    Array
    (
    	[FASTCGI_SCRIPT_NAME] => /index.php
    	[FASTCGI_PATH_INFO] =>
    )
    

Change History (1)

comment:1 by Maxim Dounin, 7 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #321.

Note: See TracTickets for help on using tickets.