Skip to content
Advertisement

Nginx not finding PHP files

I’ve been searching through all the questions asked and all answers haven’t worked. I’m trying to install Damn Vulnerable Web App to my Centos 6.9 server, but when I try to access the page, I’m greeted with a 404 File Not Found error. I can access html files perfectly, just not 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;
}


}

Can anyone help at all please?

UPDATE: After multiple attempts, below are the updated files. Now getting a ‘File Not Found’ even though the files reside within the root directory stated in the default.conf file.

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

The changes seen in other questions haven’t had any positive effect.

THIS HAS BEEN SOLVED. The location in default.conf was pointing to ‘html’ where it should have been ‘/usr/share/nginx/html’.

Advertisement

Answer

THIS HAS BEEN SOLVED. The ‘root’ in default.conf/location ~ .php$ was pointing to ‘html’ where it should have been ‘/usr/share/nginx/html’.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement