Nginx 无法执行 php 文件,提示: No input file specified.

2016-11-13 16:53:51 +08:00
 skyboy

下面的为 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;
}
3739 次点击
所在节点    NGINX
8 条回复
kungfuchicken
2016-11-13 17:25:22 +08:00
fastcgi.conf 内容?
skyboy
2016-11-13 17:30:25 +08:00
@kungfuchicken 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;
Bardon
2016-11-13 17:51:08 +08:00
php location{}中加个 root 路径进去

你这不贴全,让人家猜的话,很令人苦恼,至少一个站点的配置贴全吧,譬如 other.conf
trepwq
2016-11-13 17:53:12 +08:00
把错误日志打开,看看 access 和 error 日志里请求的 url ,应该是请求的 url 不对
timestamp
2016-11-14 10:54:46 +08:00
```
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;
}
}
```
licess
2016-11-14 11:14:27 +08:00
可能该虚拟主机网站根目录下.user.ini 里 open_basedir 设置的目录和该虚拟主机配置文件里 root 设置的不一样。
lnmp 问题反馈渠道不对。。要到 https://bbs.vpser.net/forum-25-1.html
baocaixiong
2016-11-14 12:46:28 +08:00
在 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;
#include pathinfo.conf;
return $document_root$fastcgi_script_name;
}

然后用 curl 调用,看看你的入口文件是不是正确的指向
julyclyde
2016-11-14 20:28:24 +08:00
location 不要嵌套!!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/320189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX