Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:21:39+00:00 2026-05-23T10:21:39+00:00

I managed to get this to work a while back, but on returning to

  • 0

I managed to get this to work a while back, but on returning to the cakephp project I had started it seems that whatever changes I’ve made to nginx recently (or perhaps a recent update) have broken my rewrite rules.

Currently I have:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        location /basic_cake/ {
            index  index.php;

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

        location /cake_test/ {
            index  index.php;

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

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

        # 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  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

    server {
        listen       8081;
        server_name  localhost;

        root /srv/http/html/xsp;

        location / {
            index  index.html index.htm index.aspx default.aspx;
        }

        location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

}

The problem that I have is that the css and images will not load from the webroot. Instead if I visit http://localhost/basic_cake/css/cake.generic.css, I get a page which tells me:

CakePHP: the rapid development php
framework Missing Controller

Error: CssController could not be
found.

Error: Create the class CssController
below in file:
app/controllers/css_controller.php

Notice: If you want to customize this
error message, create
app/views/errors/missing_controller.ctp
CakePHP: the rapid development php
framework

Does anybody have any ideas on how to fix this?

(I posted this on ServerFault, but I have this feeling that not many people check that site in comparison to this one, so I probably shouldn’t have bothered…)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:21:40+00:00Added an answer on May 23, 2026 at 10:21 am

    I’ve managed to solve this by adding App.base parameter to the cakephp configuration instead of using the App.baseUrl (looked the code in dispatcher.php).

    So let’s say I have the cakephp copy located in /var/www/html/cakeprj and my WWWROOT is /var/www/html:

    1. nginx host configuration

      # that's for all other content on the web host
      location / {
          root        /var/www/html;
          autoindex   off;
          index       index.php index.html index.htm;
      
          ...
      }
      
      # that's for cakephp
      location /cakeprj {
          rewrite     ^/cakeprj$ /cakeprj/ permanent;
          rewrite     ^/cakeprj/(.+)$ /$1 break;
          root        /var/www/html/cakeprj/app/webroot;
          try_files   $uri /$uri/ @cakephp;
      }
      
      # that's for all other php scripts on the web host
      location ~ \.php$ {
          root                                /var/www/html;
          fastcgi_pass                        unix:/var/lib/fcgi/php-fcgi.socket;
          ...
          include                             /etc/nginx/fastcgi_params;
      }
      
      
      # that's for cakephp execution
      location @cakephp {
          set $q $request_uri;
          if ($request_uri ~ "^/cakeprj(.+)$") {
              set $q $1;
          }
          fastcgi_param SCRIPT_FILENAME       /var/www/html/cakeprj/app/webroot/index.php;
          fastcgi_param QUERY_STRING          url=$q;
          fastcgi_pass                        unix:/var/lib/fcgi/php-fcgi.socket;
          include                             /etc/nginx/fastcgi_params;
      }
      
    2. cakephp configuration in app/config/core.php

      Configure::write('App.base', '/cakeprj');
      Configure::write('App.baseUrl', '/cakeprj/'); // seems like it doesn't matter anymore
      

    …and voila – you get nginx serving cakephp static files correctly, url passing to the cakephp dispatcher correctly and cakephp generating urls correctly as well.

    P.S. if your nginx doesn’t support try_files I believe its configuration can be rewritten with if condition and another rewrite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you managed to get Aptana Studio debugging to work? I tried following this,
A little while ago I managed to get Visual Studio 2008 (C++) into a
Tried a bunch of things but I can't get it to work consistently amid
There are a few questions that approach an answer to this question, but none
I've had this problem for a while, and no one I've talked to on
I've somehow managed to get an SVN repository into a bad state. I've moved
I've managed to get a memory 'leak' in a java application I'm developing. When
Has anyone managed to get subsonic or a variant working on Windows Mobile? We
I asked before about pixel-pushing, and have now managed to get far enough to
I'm working on drawing an SVG grid using Javascript. I've managed to get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.