LNMP部署网站 访问php文件 404

今天在一个新的服务器上部署网站,访问php文件,居然出现404
服务器是腾讯云的免费的服务器
Centos 7.2 + php7.1.7 + nginx1.12.1
安装的是lnmp一键安装包,没有使用编译的方式安装。
安装完后,添加配置文件在 /usr/local/nginx/conf/vhost
配置文件内容以下:php

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 127.0.0.1:9000
    #
    location ~ \.php($|/)  {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        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;
     }            
}

这个配置,通常来讲都是没有问题的,而后就执行下面的命令重启nginxhtml

service nginx restart

而后访问 我放在网站根目录的php文件,提示404,nginx

这我就郁闷了,文件明显存在啊,怎么会找不到呢!难道根目录设置错了?
就在根目录放了个html文件,访问一下,200,能够访问!
那么这问题就明显了,这应该是配置文件中 php的问题!或者说是 php-fpm的问题
可是我没有配置错误日志,我先在配置文件中配置错误日志,测试一下,看看报错!
看到报错,我惊呆了!请看下面:服务器

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

怎么会这样,原来应该爆500错误的,可是找不到50x.html文件,就爆了404错误。php7

那我添加上这个 50x.html 文件,访问后,显示了这个50x.html 文件,而后查看错误日志显示以下:php-fpm

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

连接失败?怎么会?测试

这里的连接应该是 nginx配置文件中配置的连接 php-fpm的配置连接,配置文件应该是没问题的,那就查看下php-fpm是否已经启动!网站

ps -aux | grep php

显示正常,如图:
图片描述spa

说明php-fpm已经启动,就查看了下 9000端口是否已经开启:3d

netstat -ant | grep 9000

没有输出,也就是说,9000端口没有开启,也就是会所php-fpm没有占用900端口

而后查看php-fpm.conf,查看其中 代码,如图:

图片描述

看到这,问题就很明显了,就是没有侦听9000端口啊,那么nginx配置中侦听的9000固然会失败
这里只须要修改下这句话就好了,以下:

listen = 9000
而后执行命令

service nginx restart

重启nginx

service php-fpm restart

重启 php-fpm

测试看看,一切OK!,再也不报错!

相关文章
相关标签/搜索