Nginx CakePHP重写问题

时间:2014-01-29 11:00:49

标签: cakephp nginx

我一直在尝试使用CakePHP运行Nginx而没有成功重写。我已经阅读了大量的文章,并且看不到我的配置文件有什么问题。

Nginx Webroot:/usr/share/nginx/html

CakePHP安装:/usr/share/nginx/html/cakephp

  

错误:您的服务器上未正确配置URL重写。

  1. 帮我配置
  2. 我不/不能使用URL重写
  3. 配置文件:

    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 个答案:

答案 0 :(得分:1)

对于vhosted域,这将有效。

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

答案 1 :(得分:0)

你的问题在这里

try_files $uri $uri/ /index.html

修改

我只是四处寻找蛋糕php,它的路由与蛋糕php有点不同,试试这个

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

然后重新加载配置