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;
}
}
访问test.ttlsa.com/index.php 出现404页面 1、检查目录是否写错了(目录写错了,一般是403),发现没有异常 2、是不是index.php文件有问题,于是新建index1.php
<?php
echo "index1.php";
?>
访问测试
# 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}
不通环境404出现的原因各不相同,这边分享作者这边出现的情况。如果看完本文还是未解决您的问题,你可以参考下以前的文章<
nginx 404>. 转载请注明出处:http://www.ttlsa.com/html/2575.html