+ -
当前位置:首页 → 问答吧 → 救命:cakephp rewrite 问题 (nginx + fastcgi),困惑8天了

救命:cakephp rewrite 问题 (nginx + fastcgi),困惑8天了

时间:2010-06-02

来源:互联网

本帖最后由 Vinsion 于 2010-06-02 03:07 编辑

需求:

有个项目用 cakephp 做的,原环境是 apache2 + php5,可以正常运行,
现在要迁移到 nginx + fastcgi ,环境已经配好(phpinfo 正常),但 cakephp
整来整去都跑不起来,

主页面(cakephp/app/webroot/index.php),可以看到,但是很粗糙,
CSS 和 图片 都不能显示,
查看图片属性:( http://images/logo.jpg )


nginx 配置:
  1. server {
  2. listen       82;
  3. #server_name  192.168.1.6;

  4. access_log  /var/log/nginx/host.access.log  main;
  5. rewrite_log on;

  6. root   /www/cakephp/app/webroot;

  7. location / {
  8. index  index.php index.htm index.html;

  9. if (-f $request_filename) {
  10.     break;
  11.     }
  12. if (-d $request_filename) {
  13.     rewrite ^/(.*)$ /index.php?url=$1 last;
  14.     break;
  15.     }

  16. }

  17. error_page   500 502 503 504  /50x.html;
  18. location = /50x.html {
  19. root   /www/;
  20. }

  21. location ~ \.php$ {
  22. fastcgi_pass   127.0.0.1:9000;
  23. fastcgi_index  index.php;
  24. fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
  25. include        /etc/nginx/fastcgi_params;
  26. #fastcgi_param SCRIPT_FILENAME /www/cakephp/app/webroot$fastcgi_script_name;
  27. #fastcgi_param  SERVER_NAME $host;
  28. #fastcgi_param  SERVER_NAME $server_name;
  29. }

  30. location ~ /(\.ht|\.git|\.svn) {
  31. deny  all;
  32. }

  33. }
复制代码
部分 error log:
  1. 2010/06/01 02:01:28 [notice] 1961#0: *1 "^/(.*)$" matches "/", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  2. 2010/06/01 02:01:28 [notice] 1961#0: *1 rewritten data: "/index.php", args: "url=", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  3. 2010/06/01 02:02:53 [notice] 1961#0: *3 "^/(.*)$" matches "/", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  4. 2010/06/01 02:02:53 [notice] 1961#0: *3 rewritten data: "/index.php", args: "url=", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  5. 2010/06/01 02:03:06 [notice] 1961#0: *5 "^/(.*)$" matches "/", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  6. 2010/06/01 02:03:06 [notice] 1961#0: *5 rewritten data: "/index.php", args: "url=", client: 192.168.1.249, server: openwrt, request: "GET / HTTP/1.1", host: "192.168.1.6:82"

  7. 2010/06/01 02:03:51 [error] 1961#0: *3 open() "/www/cakephp/app/webroot/users/login" failed (2: No such file or directory), client: 192.168.1.249, server: openwrt, request: "POST /users/login HTTP/1.1", host: "192.168.1.6:82", referrer: "http://192.168.1.6:82/"
复制代码
求各路英雄好汉出手相助,感激不尽!

作者: Vinsion   发布时间: 2010-06-02

不懂cakephp

听说cakephp已经die了。

作者: maochanglu   发布时间: 2010-06-02

location / {
index  index.php index.htm index.html;
...
}
加入root试试,或许能显示CSS和图片

作者: ylzsxdgqs   发布时间: 2010-06-02



QUOTE:
location / {
index  index.php index.htm index.html;
...
}
加入root试试,或许能显示CSS和图片
ylzsxdgqs 发表于 2010-06-02 10:43




谢谢 ylzsxdgqs 的帮助,把 root 从 server 调到 location 下面,在这之前也试过,不行:
  1. server {
  2. listen       82;
  3. #server_name  192.168.1.6;
  4. access_log  /var/log/nginx/host.access.log  main;
  5. rewrite_log on;

  6. location / {
  7. index  index.php index.htm index.html;
  8. root   /www/cakephp/app/webroot;
复制代码

作者: Vinsion   发布时间: 2010-06-02

热门下载

更多