The solution of nginx executing PHP, no input file specified

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

After configuring nginx, an error will appear when executing PHP file, and “no input file specified” will be displayed

Methods introduced online, such as modifying fastcgi_ The value of param instruction is absolute path, modifying php.ini file and so on are not the most fundamental solutions, and the key cause of the problem is not found

the root cause of “no input file specified” is the incorrect configuration of nginx, which leads to the error of CGI getting parameters . Simply put, it’s $document_ Root is not defined. In the configuration file

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Is the instruction statement written in the location block (usually matching PHP)

We know that there are three levels of relationship in the configuration file of nginx, HTTP > server > location。 If you want to use $document in location_ Root, you need to define the root instruction in the upper server block or HTTP block, so that you can use $document in the location through the inheritance relationship_ Root gets the value of root. The root instruction value defined in another location is a local variable, and its value cannot be obtained in the location matching PHP

Therefore, the solution to this problem is to move the root in the “/” location up to in the server block. Or, redefines root in the location block of PHP

Similar Posts: