在nginx上运行CakePHP

在nginx上运行CakePHP,cakephp,nginx,url-rewriting,Cakephp,Nginx,Url Rewriting,我尝试使用nginx运行一个旧的CakePHP实例 我需要将这个.htaccess重写转换成nginx1.9.3的语法 这就是我迄今为止所尝试的: server { listen 80; server_name bz.localhost; root /var/www/bz/www/cakesite; index index.html index.php; location / {

我尝试使用nginx运行一个旧的CakePHP实例

我需要将这个.htaccess重写转换成nginx1.9.3的语法

这就是我迄今为止所尝试的:

server {
        listen 80;
        server_name bz.localhost;

        root /var/www/bz/www/cakesite;
        index index.html index.php;

        location / {
                try_files $uri $uri/ /webroot/app/index.php?$args;
        }
# Another try to get the CakePHP rewrite rules:
#       location / {
#            if (!-e $request_filename) {
#                 rewrite ^/(.+)$ /webroot/$1 last;
#                 break;
#            }
#            try_files $uri $uri/ =404;
#       }
#
#       location /webroot/ {#
#           if (!-e $request_filename) {
#                 rewrite ^(.+)$ index.php?url=$1 last;
#                 break;
#           }
#       }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php5-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}
我还尝试设置另一个根:

        root /var/www/bz/www/cakesite/webroot/;


所有这些都不起作用,我总是在根文件夹中设置索引页。首先,请将您的网站添加到vhosts中,然后此配置将适用于您。如果您在本地服务器上开发,那么您可以使用子文件夹,请将/this更改为/subfoldercakephpfolder/

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