LNMP deployment website accesses PHP file 404


Today, when you deploy a website on a new server and access PHP files, 404 appears
The server is a free server of Tencent cloud
Centos 7.2 + php7.1.7 + nginx1.12.1
The LNMP one click installation package is installed without compiling.
After installation, add the configuration file in / usr / local / nginx / conf / Vhost
The configuration file is as follows:

server {
    listen       80;
    root /home/wwwroot/site;
    index index.php index.html index.htm;

    #charset koi8-r;
    access_log  /home/wwwlogs/site.access.log  main;
    error_log   /home/wwwlogs/site.error.log warn;

    # redirect server error pages to the static page /50x.html
    #error_page   500 502 503 504  /50x.html;
   location = /50x.html {
        root   /usr/share/nginx/html;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php($|/)  {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_read_timeout 150;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
        include        fastcgi_params;

Generally speaking, there is no problem with this configuration, and then execute the following command to restart nginx

service nginx restart

Then visit the PHP file I put in the root directory of the website, prompt 404,

I’m depressed. The file obviously exists. How can I not find it! Is the root directory set incorrectly?
Put an HTML file in the root directory. Visit 200 and you can access it!
Then the problem is obvious. It should be the problem of PHP in the configuration file! Or PHP FPM
But I don’t configure the error log. I first configure the error log in the configuration file and test it to see the error reports!
I was shocked to see the error report! See below:

[error] 32520#0: *1 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory)

How could this happen? Originally, there should be 500 errors, but if the 50x.html file cannot be found, there will be 404 errors.

Then I add the 50x.html file. After accessing it, the 50x.html file is displayed, and then view the error log, as shown below:

[error] 344#0: *1 connect() failed (111: Connection refused) while connecting to upstream,

Link failed? How?

The link here should be the configuration link of PHP FPM configured in nginx configuration file. The configuration file should be OK. Then check whether PHP FPM has been started!

ps -aux | grep php

The display is normal, as shown in the figure:
LNMP deployment website accesses PHP file 404

Note that PHP FPM has been started. Check whether the next 9000 port has been opened:

netstat -ant | grep 9000

No output, that is, port 9000 is not enabled, that is, PHP FPM does not occupy port 900

Then check php-fpm.conf to see the code in it, as shown in the figure:

LNMP deployment website accesses PHP file 404

When you see this, the problem is obvious. If you don’t listen on the 9000 port, of course, the 9000 listening in the nginx configuration will fail
Here, just modify the following sentence, as follows:

listen = 9000
Then execute the command

service nginx restart

Restart nginx

service php-fpm restart

Restart PHP FPM

Test and see if everything is OK!, No more errors!