Nginx找不到PHP文件

时间:2017-04-10 15:37:33

标签: php linux nginx centos

我一直在搜索所有问题并且所有答案都没有奏效。我正在尝试将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'。

1 个答案:

答案 0 :(得分:0)

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