所以我现在已经对这个问题猛烈抨击了两天,现在是时候寻求一些帮助了。我正在运行一个目前在apache上的cakephp-1.3应用程序,但是我将所有服务器都移到了nginx上。任何人都可以帮我解决这个问题吗?我认为它是一个双重问题,因为第一个nginx可能没有完全设置写重写规则。然而,我把它们从cakephp 1.3文档中删除了。第二件事是蛋糕和nginx几乎争论基础需要在哪里。无论如何这里是我的配置,它从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';
}
所以基本上发生的事情是在混合中的某个地方,cakepp在url字符串中使用/ cake /得到一个url,而cakephp认为这应该是它正在寻找的控制器。任何想法都会有所帮助。
答案 0 :(得分:0)
检查下面的配置。你错过了Cake的重写,我认为你需要通过请求传递params。我还为静态文件添加了一些不错的技巧。希望它有所帮助!
# 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;
}
答案 1 :(得分:0)
我只是想把它留在这里以防万一其他人需要它。使用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;
}
}