nginx 仅为位于根目录中的 php 提供服务

nginx 仅为位于根目录中的 php 提供服务

我有以下文件路径

http://localhost/test.php
http://localhost/playground/server.php

两者都很简单

<?php phpinfo(); ?>

问题是,nginx 将提供第一个,但嵌套在游乐场文件夹下的那个只会在我的浏览器中触发下载事件..这是什么鬼??

这是我的服务器块:

server {
  listen 80 default;
  server_name localhost;

  root   /var/www;
  index index.php;

  location / {
    autoindex on;
    index     index.html index.htm;
  }

  location ~ \.php$ {
    include /usr/local/nginx/conf/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9001;
  }
}

谢谢。

编辑 fastcfgi_params:

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_FILENAME      $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO                    $fastcgi_script_name;

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  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;

答案1

问题出在你的内部/usr/local/nginx/conf/fastcgi_params(下次将其包含在你的问题中,否则我们只是在这里猜测),fastcgi_param确切地说,尝试将其替换为:

fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

相关内容