【问题标题】:Nginx not finding PHP filesNginx 找不到 PHP 文件
【发布时间】:2017-09-05 17:58:11
【问题描述】:

我一直在搜索所有提出的问题,但所有答案都没有奏效。我正在尝试将 Damn Vulnerable Web App 安装到我的 Centos 6.9 服务器,但是当我尝试访问该页面时,我收到了 404 File Not Found 错误。我可以完美地访问 html 文件,而不是 PHP。

/etc/nginx/conf.d/default.conf:

server {
listen   80;
server_name  localhost;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm index.php;
}

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

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


}

有人可以帮忙吗?

更新: 经过多次尝试,以下是更新的文件。现在即使文件位于 default.conf 文件中所述的根目录中,也会出现“未找到文件”。

/etc/nginx/conf.d/default.conf:

server {
listen   80;
server_name  localhost;
root /usr/share/nginx/html;

location / {
   # root   /usr/share/nginx/html;
    #index  index.html index.htm index.php;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}
location ~ \.php$ {
    include        fastcgi_params;
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    try_files $uri =404;
}

}

/etc/nginx/fastcgi_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_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  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
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;

在其他问题中看到的变化没有任何积极影响。

这已经解决了。 default.conf 中的位置指向“html”,它应该是“/usr/share/nginx/html”。

【问题讨论】:

  • 您的错误日志是怎么说的?你有安装 PHP 吗?
  • 你有 php-fpm 服务在运行吗?
  • PHP-fpm 服务正在运行,日志一无所获:[10-Apr-2017 16:18:14] 注意:fpm 正在运行,pid 8875 [10-Apr-2017 16:18 :14] 注意:准备好处理连接
  • 发送curl --head <url> 以查看您获得的 HTTP 状态。如果是 PHP 问题,您将得到 5XX。如果是 nginx 问题,你会得到 4XX。 (一般。)
  • # curl --head 192.168.56.11:8080/dvwa/setup.php HTTP/1.1 400 错误请求服务器:Apache-Coyote/1.1 传输编码:分块日期:2017 年 4 月 10 日星期一 15:49:42 GMT 连接:关闭

标签: php linux nginx centos


【解决方案1】:

这已经解决了。 default.conf/location ~ .php$ 中的 'root' 指向 'html' 应该是 '/usr/share/nginx/html'。

【讨论】:

    猜你喜欢
    • 2014-08-04
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多