win nginx php7 404_nginx+yii奇怪的404问题

博客讲述了在使用Yii框架和Nginx服务器时遇到404错误的排查过程。首先检查了目录和index.php文件,确认无误后,通过创建新的index1.php测试文件排除了服务器配置问题。最终发现是由于缺少控制器文件导致的404错误,并补充了对应的控制器文件后恢复正常。文章强调了不同环境下404错误的多样性和程序问题的可能性。
摘要由CSDN通过智能技术生成

nginx+yii这么常用的组合,竟然出现了404问题,nginx rewrite规则和线上稳定运行的yii是一模一样的,怎么会错 ,来看下yii是如何出现404

先上的nginx配置

server {

listen       80;

server_name  test.ttlsa.com;

access_log  /data/logs/nginx/test.ttlsa.com.access.log  main;

index    index.php index.html index.shtml;

root /data/site/test.ttlsa.com/;

location /

{

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

}

location ~ .*\.(php)?$

{

fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi.conf;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass  unix:/var/run/phpfpm_5325.sock;

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

server{

listen      80;

server_name test.ttlsa.com;

access_log /data/logs/nginx/test.ttlsa.com.access.log main;

index   index.phpindex.htmlindex.shtml;

root/data/site/test.ttlsa.com/;

location/

{

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

}

location~.*\.(php)?$

{

fastcgi_split_path_info^(.+\.php)(/.+)$;

includefastcgi.conf;

fastcgi_paramPATH_INFO$fastcgi_path_info;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;

fastcgi_pass unix:/var/run/phpfpm_5325.sock;

}

}

访问test.ttlsa.com/index.php

出现404页面

1、检查目录是否写错了(目录写错了,一般是403),发现没有异常

2、是不是index.php文件有问题,于是新建index1.php

echo "index1.php";

?>

1

2

3

echo"index1.php";

?>

访问测试

# curl http://test.ttlsa.com/index1.php

index1.php

1

2

# curl http://test.ttlsa.com/index1.php

index1.php

好家伙,显示正常,基本上可以判断是程序有问题. 在index.php开头加上"exit;"便不再出现404问题,这肯定是程序问题,程序排查之后发现少了一个控制器文件

test.ttlsa.com/protected/controllers/IndexController.php

IndexController.php加上之后不在出现404.

备注:按理来说少了控制器文件,应该出现如下yii的报错

CHttpException

Unable to resolve the request "site/error". (/data/site/yii/framework/web/CWebApplication.php:286)

#0 /data/site/yii/framework/base/CErrorHandler.php(331): CWebApplication->runController('site/error')

#1 /data/site/yii/framework/base/CErrorHandler.php(204): CErrorHandler->render('error', Array)

#2 /data/site/yii/framework/base/CErrorHandler.php(129): CErrorHandler->handleException(Object(CHttpException))

#3 /data/site/yii/framework/base/CApplication.php(732): CErrorHandler->handle(Object(CExceptionEvent))

#4 [internal function]: CApplication->handleException(Object(CHttpException))

#5 {main}

1

2

3

4

5

6

7

8

9

10

CHttpException

Unabletoresolvetherequest"site/error".(/data/site/yii/framework/web/CWebApplication.php:286)

#0 /data/site/yii/framework/base/CErrorHandler.php(331): CWebApplication->runController('site/error')

#1 /data/site/yii/framework/base/CErrorHandler.php(204): CErrorHandler->render('error', Array)

#2 /data/site/yii/framework/base/CErrorHandler.php(129): CErrorHandler->handleException(Object(CHttpException))

#3 /data/site/yii/framework/base/CApplication.php(732): CErrorHandler->handle(Object(CExceptionEvent))

#4 [internal function]: CApplication->handleException(Object(CHttpException))

#5 {main}

不通环境404出现的原因各不相同,这边分享作者这边出现的情况。如果看完本文还是未解决您的问题,你可以参考下以前的文章.

转载请注明出处:http://www.ttlsa.com/html/2575.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值