所以我已经用头撞了这两天了,是时候寻求一些帮助了。我正在apache上运行cakephp-1.3应用程序,但是我将所有的服务器都迁移到了nginx上。有人能帮我解决这个问题吗?我认为这是一个双重问题,因为第一个nginx可能没有设置好写重写规则。但是,我从cakephp 1.3文档中提取了它们。第二件事是蛋糕和nginx几乎在争论basedir应该放在哪里。无论如何,这是我的配置,它是从cakephp文档稍微修改的,但相信我,在过去的几天里,我尝试了几乎所有可能的排列。:)
server {
listen 80;
server_name backoffice.localhost;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/cake/app/webroot;
location / {
root /var/www/cake/app/webroot;
index index.php index.html index.htm;
if (-f $request_filename) {
break;
}
rewrite ^/(.+)$ /index.php?url=$1 last;
}
location ~ .*\.php[345]?$ {
include /usr/local/nginx/conf/fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/cake/app/webroot$fastcgi_script_name;
}
}现在,如果我浏览http://backoffice.localhost,我会得到我的登录页面,就像它在我的apache服务器上运行一样,除了我没有css,奇怪的是我得到的是图片。这是日志
127.0.0.1 - - [10/Nov/2011:19:35:53 -0600] "GET /users/login HTTP/1.1" 200 1430 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"
127.0.0.1 - - [10/Nov/2011:19:35:54 -0600] "GET /img/login/images/login-btn.png HTTP/1.1" 304 0 "http://backoffice.localhost/users/login" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"
127.0.0.1 - - [10/Nov/2011:19:35:54 -0600] "GET /cake/css/admin/main.css HTTP/1.1" 200 1324 "http://backoffice.localhost/users/login" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"
127.0.0.1 - - [10/Nov/2011:19:35:54 -0600] "GET /cake/css/login/style.css HTTP/1.1" 200 1325 "http://backoffice.localhost/users/login" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"
127.0.0.1 - - [10/Nov/2011:19:35:54 -0600] "GET /cake/css/login/login-box.css HTTP/1.1" 200 1321 "http://backoffice.localhost/users/login" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"所以你可以看到css文件是正确发送的,对吧?但是为什么我没有css格式呢?好吧,让我们看看chrome附带的开发人员工具,看看它发送了什么。
Missing Controller
Error:CakeController
Error: Create the class CakeController below in file: app/controllers/cake_controller.php
class CakeController extends AppController {
var $name = 'Cake';}
所以基本上发生的事情是在混合的某个地方,cakephp得到了一个url,在url字符串中有/cake/,cakephp认为这应该是它正在寻找的一个控制器。任何想法都会有帮助。
发布于 2011-11-11 18:11:54
检查下面的配置。你错过了对Cake的重写,我认为你需要在请求中传递参数。我还为静态文件添加了一些不错的技巧。希望它能帮上忙!
# Not found this on disk?
# Feed to CakePHP for further processing!
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?url=$request_uri last;
break;
}
# Pass the PHP scripts to FastCGI server
# listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/cake/app/webroot$fastcgi_script_name;
fastcgi_intercept_errors on;
include fastcgi_params;
}
# Static files.
# Set expire headers, Turn off access log
location ~* \favicon.ico$ {
access_log off;
expires 1d;
add_header Cache-Control public;
}
location ~ ^/(img|cjs|ccss)/ {
access_log off;
expires 1d;
add_header Cache-Control public;
}发布于 2011-11-14 22:27:15
我只是想把这个留在这里以防其他人需要它。使用wrdevos代码并稍微修改一下,我想出了这个。
server {
listen 80;
server_name backoffice.localhost;
index index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/cake/app/webroot;
# Not found this on disk?
# Feed to CakePHP for further processing!
if (!-e $request_filename) {
rewrite ^/cake/(.+)$ /$1 last;
rewrite ^/(.+)$ /index.php?url=$request_uri last;
break;
}
# Pass the PHP scripts to FastCGI server
# listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/cake/app/webroot$fastcgi_script_name;
fastcgi_intercept_errors on;
include /usr/local/nginx/conf/fastcgi.conf;
}
# Static files.
# Set expire headers, Turn off access log
location ~* \favicon.ico$ {
access_log off;
expires 1d;
add_header Cache-Control public;
}
location ~ ^/(img|js|ccss)/ {
access_log off;
expires 1d;
add_header Cache-Control public;
rewrite ^/cake/(.+)$ /var/www/cake/app/weboot$1;
}
} https://stackoverflow.com/questions/8088717
复制相似问题