Answer a question

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

Answers

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

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐