douleijiang8111 2014-06-14 07:59
浏览 79
已采纳

CakePHP项目中的nginx错误“重写或内部重定向循环”

I have created a default CakePHP 2.4 project and created the Nginx configuration as follows but I am getting these errors from Nginx error log. What I have done wrong?

My environment:

  • Debian (wheezy)
  • nginx/1.2.1
  • project directory /var/www/backhaus

The error is:

$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal redirection cycle while processing "/backhaus", client: xxx.x.x.xx, server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"

Here is my config from ../sites-available/default:

location /backhaus {
   root /var/www/backhaus/app/webroot/;
   index index.php;
   rewrite ^/* /backhaus;
   location ~ ^/(.+\.php)$ {
           try_files $uri $uri/ =404;
           include /etc/nginx/fastcgi_params;
           fastcgi_pass unix:/var/run/php5-fpm.sock;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   }
 }
  • 写回答

1条回答 默认 最新

  • duanbichou4942 2014-06-14 08:12
    关注

    Your error is this:

    $ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal redirection cycle while processing "/backhaus", client: xxx.x.x.xx, server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"

    And the error clearly states:

    …redirection cycle while processing "/backhaus"…

    So now, let’s look at your posted Nginx config:

    location /backhaus {
      root /var/www/backhaus/app/webroot/;
      index index.php;
      rewrite ^/* /backhaus;
      location ~ ^/(.+\.php)$ {
              try_files $uri $uri/ =404;
              include /etc/nginx/fastcgi_params;
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    }
    

    It seems like the issue is your location is /backhaus but then you are redirecting any traffic going to /backhaus to /backhaus via this line:

    rewrite ^/* /backhaus;
    

    So I would recommend just removing that rewrite line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog