cakephp - 如何在nginx中配置cakephp

标签 cakephp nginx memcached centos vhosts

目前我正在使用 nginx 开发 cakephp。我在运行 Nginx 和 Fact CGI 的 Centos 服务器上设置了 cakephp 环境。问题是我无法在我的虚拟主机中正确设置重写规则,以便 cake 正确渲染页面,即样式等。 我的 .conf 文件是 -

#The default server

server {    
listen  80 default_server;    
server_name  1 23.123.123.123;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
}


error_page  404              /404.html;
location = /404.html {
    root   /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny  all;
}
}

最佳答案

下面 Luchomolina 的回答让我朝着正确的方向开始。但是,CSS 和 JS 文件不再对非顶级 URL 起作用,例如/posts 有效,但/posts/title123 无效。

这就是最终为我工作的内容:

location / {
   if (-f $request_filename) {
       break;
   }
   if (!-f $request_filename) {
      rewrite ^/(.+)$ /index.php?url=$1 last;
      break;
   }

   set $new_uri $uri;
} 

关于cakephp - 如何在nginx中配置cakephp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14704982/

相关文章:

python - 以相反的顺序处理行

php - 在 PHP 中保存缓存对象的 View 计数的最佳位置?

ruby - 使用 dalli 运​​行 memcached 时出现连接错误

php - Cakephp 读写json文件。

php - CakePHP:尝试生成模式时出错

redirect - Nginx 万维网。到非 www。重定向不工作

memcached - memcache,多实例与单实例

php - CakePHP 查询生成器没有为新列提供别名

cakephp - 如何在cakephp 2.4中实现JsonP

linux - 在 CentOS 中使用 Nginx 作为 Apache 上 wordpress 的反向代理