技术解析

Nginx 无法执行 php 文件,提示: No input file specified.
0
2021-05-20 22:30:43
idczone

下面的为 www.my123.com.conf 文件,为何其它的两个站点,也用的这个模板,都能正常执行 php 文件,而这个一执行 www.my123.com/任意存在的.php 文件,都提示: No input file specified.重启几次都无果。

执行 www.my123.com/.html www.my123.com/.jpg 都正常。

server { listen 80; #listen [::]:80; server_name www.my123.com my123.com; if ($host != 'www.my123.com' ) { rewrite ^/(.*)$ http://www.my123.com/$1 permanent; }
index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/www.my123.com;

  include other.conf;
 #error_page   404   /404.html;
 location ~ [^/]\.php(/|$)
 {
    # comment try抗投诉服务器_files $uri =404; to enable pathinfo
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    #include pathinfo.conf;
  }

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

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

    access_log  /home/wwwlogs/www.my123.com.log  access;
}

fastcgi.conf 内容?

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

php location{}中加个 root 路径进去
你这不贴全,让人家猜的话,很令人苦恼,至少一个站点的配置贴全吧,譬如 other.conf

把错误日志打开,看看 access 和 error 日志里请求的 url ,应该是请求的 url 不对

```
server {
listen 80;
server_name laravel.dev;
root /usr/local/var/www/laravel.dev/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
```

可能该虚拟主机网站根目录下.user.ini 里 open_basedir 设置的目录和该虚拟主机配置文件里 root 设置的不一样。
lnmp 问题反馈渠道不对。。要到 https://bbs.vpser.net/forum-25-1.html

在 nginx 的配置段中加入:
location ~ [^/]\.php(/|$)
{
comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
pathinfo.conf;
return $document_root$fastcgi_script_name;
}
然后用 curl 调用,看看你的入口文件是不是正确的指向

location 不要嵌套!!

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服