Solution to "No input file specified" in nginx+php

Solution to "No input file specified" in nginx+php

Today, the error "No input file specified" suddenly appeared in my local development environment. I checked my configuration files, configuration paths, and permissions repeatedly and found that there were no problems. After repeated investigations, the problem was finally found. The problem and solution are shared as follows:

Cause Analysis

I downloaded an open source tp5 project from GitHub, and my local website had no problems running before. However, after installing this open source project, I found that other local websites were inaccessible. Access is No input file specified error. I also looked for solutions on the Internet, but none of them worked. It seems that this error is a bit strange.

After repeated attempts, the problem was solved after restarting the computer. However, after running the downloaded tp5 open source project again, other websites showed the error No input file specified, and only this one website ran without any problems.

Based on this, the error was localized in the nginx configuration file of the open source project. Let's take a look at the configuration file:

server {
  listen 80;
  server_name local.test.com;
  access_log /data/wwwlogs/local.test.com.log combined;
  error_log /data/wwwlogs/local.test.com_error.log error;
  index index.html index.htm index.php;
  root /data/php/test;

  add_header X-Powered-Host $hostname;
  fastcgi_hide_header X-Powered-By;

  if (!-e $request_filename) {
    rewrite ^/(.+?\.php)/?(.*)$ /$1/$2 last;
    rewrite ^/(.*)$ /index.php/$1 last;
  }

  location ~ \.php($|/){
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
    set $real_script_name $fastcgi_script_name;
    if ($real_script_name ~ "^(.+?\.php)(/.+)$") {
      set $real_script_name $1;
    }
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param PHP_VALUE open_basedir=$document_root:/tmp/:/proc/;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
    access_log off;
    error_log off;
    expires 30d;
  }

  location ~ .*\.(js|css)?$ {
    access_log off;
    error_log off;
    expires 12h;
  }

In the above configuration, the rest are conventional configurations. Because I use cgi. There is a line in the fastcgi parameters that you may have noticed.

fastcgi_param PHP_VALUE open_basedir=$document_root:/tmp/:/proc/;

That's it. The main function of this sentence is to set the operable directory of fastcgi to prevent cross-site, and limit open_basedir to the directory of this project and /tmp/ and /proc/.

Problem Solving

I just said that there is an additional statement to prevent cross-site in the configured fastcgi configuration. Then this sentence actually affects the parameters of the entire fastcgi. Because the path of my other website is a directory like /data/php/xxx/, but not in the directory /data/php/test/ of this open source project, fastcgi cannot be found.
So add # before this sentence to comment it out or delete it and restart the system or restart nginx.

Online deployment recommendations

So should we use this sentence or not? Of course it is possible in an online environment. In online project deployment, it is best not to use variables such as $document_root in open_basedir. If there are multiple projects in an online server, all projects can be placed in a unified directory. For example, my online directory is wwwroot where other websites are placed. For example, /wwwroot/test1 /wwwroot/test2, I can configure it as

fastcgi_param PHP_VALUE open_basedir=/wwwroot/:/tmp/:/proc/;

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Analysis of the automatic loading and autonomous object creation operation examples of the PHP framework CI (codeigniter)
  • Solution to the "No input file specified" problem in PHP5.6+
  • PHP filters the htmlspecialchars() function to convert predefined characters into HTML entity usage analysis
  • Summary of enabling Oracle OCI8 extension for Plesk PHP7
  • PHP htmlspecialchars() function usage and example explanation
  • PHP htmlspecialchars_decode() function usage explanation
  • PHP htmlspecialchars() function example code and usage
  • PHP CI framework learning explanation

<<:  Detailed installation tutorial for MySQL zip archive version (5.7.19)

>>:  mysql5.7.19 zip detailed installation process and configuration

Recommend

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

How to configure Http, Https, WS, and WSS in Nginx

Written in front In today's Internet field, N...

Detailed explanation of how to use the Vue date time picker component

This article example shares the specific code of ...

Detailed explanation of samba folder sharing server configuration under centos

1. Introduction Recently I found that there are m...

Use iptables and firewalld tools to manage Linux firewall connection rules

Firewall A firewall is a set of rules. When a pac...

Nginx reverse proxy and load balancing practice

Reverse Proxy Reverse proxy refers to receiving t...

Detailed explanation of the principle of creating tomcat in Eclipse

When creating a tomcat server on a local eclipse,...

Detailed explanation of setting up DNS server in Linux

1. DNS server concept Communication on the Intern...

How to modify the initial password of a user in mysql5.7

When users install MySQL database for the first t...

How to Develop a Progressive Web App (PWA)

Table of contents Overview Require URL of the app...

Detailed explanation of docker nginx container startup and mounting to local

First, the structure inside the nginx container: ...

How to modify the IP restriction conditions of MySQL account

Preface Recently, I encountered a requirement at ...

How to optimize MySQL query speed

In the previous chapters, we introduced how to ch...

How to use CSS custom variables in Vue

Table of contents The CSS custom variable functio...