title: Run CakePHP on nginx
body: <p>I try to get an old CakePHP instance running with nginx.</p>
  
  <p>I need to translate this .htaccess rewrite into the syntax of nginx 1.9.3.</p>
  
  <p>This is what I tried so far:</p>
  
  <pre><code>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;
          }
  }
  </code></pre>
  
  <p>I also tried to set another root:</p>
  
  <pre><code>        root /var/www/bz/www/cakesite/webroot/;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>        root /var/www/bz/www/cakesite/webroot/app/;
  </code></pre>
  
  <p>None of this worked, I always et the index page in the root folder</p>