title: CakePHP and Nginx configuration
body: <p>So I've been tasked with creating a site using CakePHP, so I downloaded the latest 2.2.3, and I need to configure it on my local nginx 1.2.4 server.</p>
  
  <p>I have the <code>server_block</code> working, but for some reason I can't load any css. The test home page also reports that url rewriting isn't working properly.</p>
  
  <p>I've been reading a number of articles and questions, but none seem to be able to solve the issue. So far I've referenced,  </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/8088717/issue-with-cakephp-application-running-on-nginx-1-0-8-subdirectory">Issue with Cakephp application running on nginx 1.0.8 + subdirectory</a></li>
  <li><a href="http://book.cakephp.org/2.0/en/installation/advanced-installation.html#pretty-urls-on-nginx" rel="nofollow noreferrer">http://book.cakephp.org/2.0/en/installation/advanced-installation.html#pretty-urls-on-nginx</a></li>
  <li><a href="http://www.littlehart.net/atthekeyboard/2007/09/14/configuring-cakephp-to-work-with-nginx/" rel="nofollow noreferrer">http://www.littlehart.net/atthekeyboard/2007/09/14/configuring-cakephp-to-work-with-nginx/</a></li>
  <li><a href="http://www.littlehart.net/atthekeyboard/2009/01/25/cakephp-nginx-configuration-update/" rel="nofollow noreferrer">http://www.littlehart.net/atthekeyboard/2009/01/25/cakephp-nginx-configuration-update/</a></li>
  <li><a href="http://kvz.io/blog/2010/02/24/cakephp-and-nginx/" rel="nofollow noreferrer">http://kvz.io/blog/2010/02/24/cakephp-and-nginx/</a>  </li>
  </ul>
  
  <p>My css links look like this,<br>
  <code>&lt;link rel="stylesheet" type="text/css" href="/Users/david/Sites/example.com/css/cake.generic.css" /&gt;</code>  </p>
  
  <p>I need to figure out why Nginx isn't letting my CSS load. So far I can only find out that it's appending the <code>$_SERVER['DOCUMENT_ROOT']</code> to all my links which obviously means my css will be incorrectly linked. I need to find out who to stop cakephp from picking up this extra information. Links are being passed into the HtmlHelper as follows <code>string '/Users/david/Sites/example.com//Users/david/Sites/example.com/css/cake.generic.css' (length=86)</code></p>
  
  <p>Currently my nginx config server block looks like the following.  </p>
  
  <pre><code>server { 
      server_name  example.com;
  
      root   /Users/david/Sites/example.com/app/webroot/;
  
      access_log /usr/local/var/log/nginx/example.com.access.log;
      error_log /usr/local/var/log/nginx/example.com.error.log;
  
      listen       80;
      rewrite_log on;
  
      # rewrite rules for cakephp
      location / {
          index  index.php index.html;
  
          # If the file exists as a static file serve it 
          # directly without running all
          # the other rewite tests on it
          if (-f $request_filename) { 
              break; 
          }
  
          if (!-f $request_filename) {
              rewrite ^(.+)$ /index.php?url=$1 last;
              break;
          }
      }
  
      location ~* \favicon.ico$ {
          expires 6m;
      }
      location ~ ^/img/ { 
          expires 7d; 
      } 
  
      location ~ \.php$ {
          fastcgi_pass  127.0.0.1:9001;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param SERVER_NAME example.com;
          include       fastcgi_params;
      }
  
      location ~ /\.ht {
          deny  all;
      }
  }
  </code></pre>
  
  <p><strong>FastCGIParams</strong>  </p>
  
  <pre><code>fastcgi_param  QUERY_STRING       $query_string;
  fastcgi_param  REQUEST_METHOD     $request_method;
  fastcgi_param  CONTENT_TYPE       $content_type;
  fastcgi_param  CONTENT_LENGTH     $content_length;
  
  fastcgi_param  SCRIPT_NAME        $request_filename;
  fastcgi_param  REQUEST_URI        $request_uri;
  fastcgi_param  DOCUMENT_URI       $document_uri;
  fastcgi_param  DOCUMENT_ROOT      $document_root;
  fastcgi_param  SERVER_PROTOCOL    $server_protocol;
  fastcgi_param  HTTPS              $https if_not_empty;
  
  fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
  
  fastcgi_param  REMOTE_ADDR        $remote_addr;
  fastcgi_param  REMOTE_PORT        $remote_port;
  fastcgi_param  SERVER_ADDR        $server_addr;
  fastcgi_param  SERVER_PORT        $server_port;
  fastcgi_param  SERVER_NAME        $server_name;
  
  # PHP only, required if PHP was built with --enable-force-cgi-redirect
  fastcgi_param  REDIRECT_STATUS    200;
  
  fastcgi_connect_timeout 60;
  fastcgi_send_timeout 180;
  fastcgi_read_timeout 180;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 256k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;
  fastcgi_intercept_errors on;
  </code></pre>