【问题标题】:nginx: Map single static URL to a PHP file ?No input file specifiednginx:将单个静态 URL 映射到 PHP 文件?未指定输入文件
【发布时间】:2019-06-22 17:16:03
【问题描述】:

我需要将单个静态 URL 映射到我在配置文件中使用的特定 PHP 文件

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;

        location /reset {
           root html/sys;
           try_files /index.php /index.php;
            fastcgi_pass    127.0.0.1:9000; //PHP server
            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_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;    
            include         fastcgi_params;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Result = ("No input file specified.") 响应

如果我将返回 (try_files index.html;) 并删除 php 代理,那么它将返回 html 索引页面,此问题仅在它尝试返回 php 页面时发生

【问题讨论】:

    标签: php nginx configuration


    【解决方案1】:

    您将文档根目录设置为html/sys,这与 Nginx 安装相关。 PHP-FPM 可能不知道如何解决。

    要么使用绝对路径:

    root /path/to/html/sys;
    

    或者使用$realpath_root,这是$document_root的绝对版本:

    fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;    
    

    或者使用更少打字的$request_filename:

    fastcgi_param  SCRIPT_FILENAME  $request_filename;    
    

    您应该将include fastcgi_params; 放在您的fastcgi_param 语句之前,因为您的参数可能会被该文件中指定的值默默地覆盖。

    【讨论】:

    • 感谢您的回复我将根添加到 c:\\nginx-1.14.2\\html\\sys 并尝试了 c:/nginx-1.14.2/html/sys 然后更改了 fastcgi_param 但仍然没有指定输入文件。
    • 当我运行 fastcgi_param SCRIPT_FILENAME c:\\nginx-1.14.2\\html\\sys\\index.php 它的工作原理是你说它与绝对路径有关:非常感谢理查德·史密斯!请给他投票,我要小代表
    猜你喜欢
    • 2012-12-31
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 2018-10-30
    • 2020-03-09
    相关资源
    最近更新 更多