V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
skyboy
V2EX  ›  NGINX

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

  •  
  •   skyboy · 2016-11-13 16:53:51 +08:00 · 3656 次点击
    这是一个创建于 2722 天前的主题,其中的信息可能已经有所发展或是发生改变。

    下面的为 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;
    }
    
    8 条回复    2016-11-14 20:28:24 +08:00
    kungfuchicken
        1
    kungfuchicken  
       2016-11-13 17:25:22 +08:00 via Android
    fastcgi.conf 内容?
    skyboy
        2
    skyboy  
    OP
       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
        3
    Bardon  
       2016-11-13 17:51:08 +08:00
    php location{}中加个 root 路径进去

    你这不贴全,让人家猜的话,很令人苦恼,至少一个站点的配置贴全吧,譬如 other.conf
    trepwq
        4
    trepwq  
       2016-11-13 17:53:12 +08:00 via iPhone
    把错误日志打开,看看 access 和 error 日志里请求的 url ,应该是请求的 url 不对
    timestamp
        5
    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
        6
    licess  
       2016-11-14 11:14:27 +08:00
    可能该虚拟主机网站根目录下.user.ini 里 open_basedir 设置的目录和该虚拟主机配置文件里 root 设置的不一样。
    lnmp 问题反馈渠道不对。。要到 https://bbs.vpser.net/forum-25-1.html
    baocaixiong
        7
    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
        8
    julyclyde  
       2016-11-14 20:28:24 +08:00
    location 不要嵌套!!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2879 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:43 · PVG 17:43 · LAX 02:43 · JFK 05:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.