Home  >  Article  >  Backend Development  >  How to solve the No input file specified error in nginx+php

How to solve the No input file specified error in nginx+php

小云云
小云云Original
2018-03-16 11:45:576546browse

今天在自己本地的开发环境突然出现了No input file specified错误,反复检查返现自己的配置文件和配置路径以及权限都没有问题。经过反复的排查终于发现了问题,本文主要和大家分享nginx+php出现No input file specified错误如何解决,希望能帮助到大家。

问题原因分析

在GitHub上下载了一个开源的tp5项目,之前自己本地的网站运行都没有问题。但是安装了这个开源项目后就发现本地其他网站都无法访问了。访问就是No input file specified错误。在网上也找了解决办法,但是都不是,看来这个错误有点儿诡异。
后来反复尝试,重启电脑后问题得到解决但是再次运行下载的tp5开源项目后其他网站又出现了这样的错误No input file specified 而且只有这一个网站运行没有问题。
据此将错误圈定在该开源项目的nginx配置文件中。再来看看该配置文件:

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;
    }

在以上的配置中其他都是常规的配置。因为我使用cgi。在fastcgi参数中有一行可能大家也注意到了。

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

就是这句。这句的主要作用是设置fastcgi的可操作目录从而防止跨站的,将open_basedir限定在了本项目的目录和/tmp/以及/proc/中。

问题解决

刚刚说了是在配置的fastcgi配置中多了一句防止跨站的语句。那么这句话他其实是影响了整个fastcgi的参数,这样因为我的其他网站的路径是/data/php/xxx/这样的目录,而不在本开源项目的目录/data/php/test/所以fastcgi就无法找到。
所以在这句之前加#注释这句或者删除这句重启系统或重启nginx就可以了。

线上部署的建议

那么到底要不要使用这句呢?在线上环境中当然是可以的。在线上项目部署中对于open_basedir中最好别使用$document_root这样的变量。如果有多个项目在线上服务器中那么可以把所以项目放置在一个统一的目录中。例如我的线上是wwwroot目录下放置其他网站。例如/wwwroot/test1   /wwwroot/test2那么我可以配置为

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

相关推荐:

Windows下配置Nginx+PHP

配置Nginx+PHP的正确思路与过程 nginx apache nginx php nginx rewrite

Nginx+php-fpm 502 504问题 php-fpm nginx 504 java nginx php 50

The above is the detailed content of How to solve the No input file specified error in nginx+php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn