1
votes

I have been trying to get Nginx with CakePHP running with no success with regards the rewrite. I have read tons of articles and can't see anything wrong with my config file.

Nginx Webroot: /usr/share/nginx/html

CakePHP Installation: /usr/share/nginx/html/cakephp

Error: URL rewriting is not properly configured on your server.

  1. Help me configure it
  2. I don't / can't use URL rewriting

Config file:

server {
        listen 80;

        root /usr/share/nginx/html;
        index index.php index.html index.htm;

        server_name localhost;

        location / {
                try_files $uri $uri/ /index.html;
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

        # Deny access to .htaccess files,
        location ~ /(\.ht|\.git|\.svn) {
                deny  all;
        }
}
2
What is not working? Is it the /doc/ location block? - Tan Hong Tat
Cakephp will launch its starter page with the error regarding the rewrite not configured properly. As a result there is no css, images etc on the page. - Aeolos

2 Answers

1
votes

For vhosted domain, this will work.

location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    rewrite ^/$ /app/webroot/ break;
    rewrite ^(.*)$ /app/webroot/$1 break;

}
location /app/ {
    rewrite ^/$ /webroot/ break;
    rewrite ^(.*)$ /webroot/$1 break;
}
location /app/webroot/ {
    if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
    }
}   
0
votes

Your problem is here

try_files $uri $uri/ /index.html

EDIT:

I just looked around for cake php, it's routing is a bit different for cake php, try this instead

try_files $uri $uri/ /index.php?url=$request_uri;

Then reload the config afterwards