Why does PATH_INFO in nginx affect $ _ SERVIER ['php _ SELF ']?

Source: Internet
Author: User
Problem Found: Use ThinkPHP3.2.2 to deploy the website on nginx, set URL_MODEL2, and use the U method to generate a link locally, for example: publicindex is deployed on nginx but there is a problem where the URL is generated. publicindex trace the ThinkPHP source code in ThinkPH... problems found:
Use ThinkPHP3.2.2 to deploy the website in nginx, set URL_MODEL = 2, and use the U method to locally generate a link, for example,/public/index.
However, a problem occurs when deployed on nginx. The URL generates./public/index.

The following code is found in the ThinkPHP. php file by searching for the ThinkPHP source code:

If (IS_CGI) {// CGI/FASTCGI mode $ _ temp = explode ('. php ', $ _ SERVER ['php _ SELF']); define ('_ PHP_FILE _', rtrim (str_replace ($ _ SERVER ['HTTP _ host'], '', $ _ temp [0]. '. php '),'/');} else {define (' _ PHP_FILE _ ', rtrim ($ _ SERVER ['script _ name'], '/'));}

This is the root cause of the problem.
Access: http: www.xxx.com/public/index
Under apache$_SERVER['PHP_SELF']Display./index. php/public/index
While nginx is blank

Access: http: www.xxx.com/index.php/public/index
Under apache$_SERVER['PHP_SELF']Display./index. php/public/index
Display/public/index in nginx

At last, it was found that the PATH_INFO feature in nginx encountered a strange problem.
In my nginx, The PATH_INFO section is configured as follows:

Fastcgi_split_path_info ^ (. +? \. Php) (/. *) $; set $ path_info $ fastcgi_path_info; fastcgi_param PATH_INFO $ path_info; # try_files $ fastcgi_script_name = 404 if this line of PHP_SELF is set;

Reply content:

Problems found:
Use ThinkPHP3.2.2 to deploy the website in nginx, set URL_MODEL = 2, and use the U method to locally generate a link, for example,/public/index.
However, a problem occurs when deployed on nginx. The URL generates./public/index.

The following code is found in the ThinkPHP. php file by searching for the ThinkPHP source code:

If (IS_CGI) {// CGI/FASTCGI mode $ _ temp = explode ('. php ', $ _ SERVER ['php _ SELF']); define ('_ PHP_FILE _', rtrim (str_replace ($ _ SERVER ['HTTP _ host'], '', $ _ temp [0]. '. php '),'/');} else {define (' _ PHP_FILE _ ', rtrim ($ _ SERVER ['script _ name'], '/'));}

This is the root cause of the problem.
Access: http: www.xxx.com/public/index
Under apache$_SERVER['PHP_SELF']Display./index. php/public/index
While nginx is blank

Access: http: www.xxx.com/index.php/public/index
Under apache$_SERVER['PHP_SELF']Display./index. php/public/index
Display/public/index in nginx

At last, it was found that the PATH_INFO feature in nginx encountered a strange problem.
In my nginx, The PATH_INFO section is configured as follows:

Fastcgi_split_path_info ^ (. +? \. Php) (/. *) $; set $ path_info $ fastcgi_path_info; fastcgi_param PATH_INFO $ path_info; # try_files $ fastcgi_script_name = 404 if this line of PHP_SELF is set;

This $ _ SERVER has a lot to do with SERVER configuration.

Try_files $ fastcgi_script_name = 404; you can remove it. $ _ SERVER ['php _ SELF '] will have

You do not need to remove try_files $ fastcgi_script_name = 404. This configuration addresses the security vulnerability when cgi. fix_pathinfo is set to 1 in php. ini. This error is caused by the configuration of cgi. fix_pathinfo = 0 on the php. ini server of the landlord.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.