centos 一次 404 not found 排错经过

本次项目原因:

目前公司有三套环境:

1、正式环境

2、测试环境

3、集成环境

新配小程序业务在正式/测试环境运行都正常,但配到本地集成环境服务器时报404 not found。

开始耗费脑细胞:

首先访问本地域名发现404是由php框架展现的,并不是由nginx展现。

跟开发对了下,开发同学坚持认为是因为nginx路由转发有问题,导致php路由重写未生效。

排查nginx.conf文件

server {
    listen       80;
    server_name  ci.bidding.gufeibao.com;
    access_log  /home/wwwlogs/ci.bidding.gufeibao.com.access.log main;
    error_log  /home/wwwlogs/ci.bidding.gufeibao.com.error.log;

    set $root /home/www/gfbphp/gfbbidding;
    root "$root/public";
    location / {
        if ($request_method = 'OPTIONS') {
            return 204;
        }
        index index.php index.html;
        try_files $uri $uri/ /index.php?$query_string;
    }

        location ~\.php$ {
          fastcgi_pass unix:/tmp/php-cgi.sock;
          fastcgi_index index.php;
          include fastcgi_params;        fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
    error_page 404 /404.html;
        location = /404.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

可以很准确的看到路由转发是已经配上的。

try_files $uri $uri/ /index.php?$query_string;

 去看了下报错日志

 因为我也是个半吊子..开始的时候看到fastcgi去找了9000,还以为是nginx去找php时找错了,因为php的启动方式为 /tmp/php-cgi.sock。

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = gfb
listen.group = gfb
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 60
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 60
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

接着去查看9000端口,不出所料是空的没错

 紧接着噩梦就来了。。

1、首先把php启动方式更改为9000

listen = 127.0.0.1:9000

重启php,并把nginx里 fastcgi_pass 指向9000

 fastcgi_pass 127.0.0.1:9000;

再次访问发现依旧404,报错与之前一样。

2、接着开始去比对集成环境的conf文件和另外两个环境有什么不同

该代码段为测试环境代码

   # Load configuration files for the default server block.
    location / {
        index index.php index.html *;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PATCH, POST, PUT, DELETE';
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        if ($request_method = 'OPTIONS') {
            return 204;
        }
        try_files $uri $uri/ /index.php?$query_string;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        }
    error_page 404 /404.html;
    location = /404.html {
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
}

发现测试环境有配置跨域访问add_header

但本项目不涉及到跨域,只是php项目

为了保险我把集成环境的conf添加了add_header

再次访问依旧404...

3、到了现在我已经耗费了2个多小时,我已经开始怀疑是开发同学的代码有问题了,就让开发同学在流水线重新部署一次代码,结果发现还是404,并且开发同学还是坚持认为是nginx配置有问题。。。

4、到了现在我已经疲了,我把测试环境的conf直接替换到集成环境,毫无意义,依旧404

5、ok换个思路,我把集成环境404的conf,域名更换为另一个项目域名,root路径也指向另一个项目的代码库,其余不更改,发现可以正常访问。

到了这步我可以确定nginx是没有问题的,问题出在开发同学那里。

经过很久很久他的排查,发现是.env文件没有放进去......

我他妈!草!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超能力大雄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值