解决Yii2使用Nginx报错:rewrite or internal redirection cycle while processing十个index.php连写

技术分享 · ycjnx · 于 5年前 发布 · 12296 次阅读

问题描述:

网站首页显示正常,但点击产品或栏目链接都报500错误,Nginx日志显示错误:

2018/05/14 17:52:28 [error] 13566#0: *8 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/customer/ajax", client: 127.0.0.1, server: www.emall.com, request: "GET /customer/ajax?currentUrl=http%3A%2F%2Fwww.emall.com%2F&product_id= HTTP/1.1", host: "www.emall.com", referrer: "http://www.emall.com/"

问题解决:

正确的Nginx配置:(在Yii2中使用PrettyURL这样配置是可以的)

[webadmin@centos7 eltmall] #24> vim /etc/nginx/nginx.conf

......
......
        location / {
            # 各种尝试之后所得的结果,就是一句代码,OK!
            try_files $uri $uri/ /index.php?$args;  
        }
......
......

错误的Nginx配置:(至少在我的机器中是错误的)

[webadmin@centos7 eltmall] #24> vim /etc/nginx/nginx.conf

......
......
        location / {
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
            }  
        }
......
......

[webadmin@centos7 eltmall] #24>

最后上个图:

共收到 2 条回复
Fecmall#15年前 0 个赞

nginx去掉index.php 是有各种各样的错误,多谢分享

已经将你的这个最为一个案例放到了:http://www.fecshop.com/topic/398

ycjnx#25年前 0 个赞

好的,老大

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics