zoukankan      html  css  js  c++  java
  • Windows7安装 nginx+php 后访问.php文件出现 “No input file specified.” 的解决办法

    在Windows7上安装了Nginx+PHP,参考教程为 https://www.cnblogs.com/anlia/p/5916758.html

    启动 nginx 后,在浏览器中输入localhost可以看到成功访问nginx的页面:
    Nginx 欢迎页面

    在html目录中添加了一个phpinfo.php文件,内容为:

    <?php
    phpinfo();
    ?>
    

    在浏览器中输入:

    localhost:/phpinfo.php

    页面却显示:
    无法访问php文件

    后来意识到是 nginx 安装目录下的 conf/nginx.conf 文件配置不正确:

            location ~ .php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
            }
    

    如上配置中的 SCRIPT_FILENAME , /scripts 是不存在的路径,应当更改为存放 .php 文件的目录路径:

            location ~ .php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  D:/nginx-1.15.3/html/$fastcgi_script_name;
                include        fastcgi_params;
            }
    

    或者使用 $document_root 来代替,该变量即为 location 配置块中的 root 指定的目录 ‘html’。


    反思总结

    回头再看那篇参考教程,里面的配置就是把 SCRIPT_FILENAME 写成 '$document_root/$fastcgi_script_name' (原文中 $document_root 后面少了一个 '/'),当时因为在配置文件中没有找到 $document_root 的定义,所以就没放在心上,以为是各自的环境不一样的原因,现在看来,$document_root 是 nginx 的一个内置环境变量,专门用来指代当前 location 配置块中的 root 变量。


    补充:

    刚才试验了一下,发现

    $document_root/$fastcgi_script_name (有'/')

    $document_root$fastcgi_script_name (无'/')

    都可以使 nginx 正常找到 .php 文件

  • 相关阅读:
    hdu 5734 Acperience
    报错解决
    测试代码出错
    fast rcnn训练自己数据小结
    top命令
    读csv文件
    计算机的屏幕坐标
    用virtualenv构建一个新的python环境,这个新的环境在这个创建的文件夹下
    python tips
    将目录下所有文件名修改为统一格式
  • 原文地址:https://www.cnblogs.com/dongling/p/9573084.html
Copyright © 2011-2022 走看看