问题与Cakephp应用程序运行在nginx 1.0.8 +子目录 [英] Issue with Cakephp application running on nginx 1.0.8 + subdirectory

查看:87
本文介绍了问题与Cakephp应用程序运行在nginx 1.0.8 +子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在已经两天了,我的头撞到这一天,并且要求一些帮助。我运行一个cakephp-1.3应用程序当前在apache,但im将我们的所有服务器移动到nginx。谁能帮助我想出这个?我认为它的双重问题的意义是,第一个nginx可能没有相当的写重写规则设置。我把它们从cakephp 1.3文档中。第二件事是蛋糕和nginx几乎争论基地需要在哪里。无论如何这里是我的配置,它是从cakephp文档稍微修改,但相信我在最近几天ive尝试了只是每一个可能的排列。 :)

So ive been banging my head against this one for two days now and its time to ask for some help. Im running a cakephp-1.3 application currently on apache but im moving all of our servers over to nginx. Can anyone help me figure this out? I think its a dual issue in the sense that first nginx may not have quite the write rewrite rules set up. I pulled them out of the cakephp 1.3 documentation however. The second thing is cake and nginx are almost arguing over where the basedir needs to be. Anyway here is my config, it is slightly modified from the cakephp documentation but trust me over the last few days ive tried just about every permutation possible. :)

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,奇怪的是,我得到的图像。 Heres日志

Right now if i browse to http://backoffice.localhost i get my log in page just as its running on my apache sever except i have no css, oddly enough i get images. Heres the logs

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格式化?好,让我们来看看开发者工具包括铬在发送什么。

So you see that the css files are sent correctly right? But why dont i have css formatting? Well lets look in the developer tools included with chrome at whats being sent.

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字符串中的url和cakephp认为这应该是一个控制器它寻找任何想法将是有益的。

So basically whats happening is somewhere in the mix cakephp is getting a url with /cake/ in the url string and cakephp thinks this should be a controller its looking for. Any thoughts would be helpful.

推荐答案

我想在这里离开这里,以防任何人需要它使用wrdevos代码和修改它一点我。

I just wanted to leave this here in case anyone else needs it. Using wrdevos code and modifying it a little i came up with this.

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;
}
} 

这篇关于问题与Cakephp应用程序运行在nginx 1.0.8 +子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆