nginx:将单个静态URL映射到PHP文件?未指定输入文件

时间:2019-01-29 14:37:24

标签: php nginx configuration

我需要将单个静态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;
        }
    }
}

结果=(“未指定输入文件。”)作为响应

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

1 个答案:

答案 0 :(得分:0)

您将文档根目录设置为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之前,{{1}}放在之前,因为您的参数可能会被该文件中指定的值默默覆盖。

相关问题