This is my Blog.

It's full of opinions on a wide range of stuff.

NGINX (Engine-X) Rewrite Rules For CakePHP

I've been doing some work with NGINX of late and anyone familiar with CakePHP will know that it ships out of the box with Apache .htaccess files to make sure that the URL's are devoid of there query string.

Anyway, enough talk, if you want to host cakephp on NGINX, you'll need to use a vhost like so:

    server { 
        listen       80;
        access_log  /var/www/logs/somedomain.access.log  main;
        error_log   /var/www/logs/somedomain.error.log info;
        rewrite_log on;

        # rewrite rules for cakephp
        location / {
          root   /var/www/sites/;
          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) { 
          if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;

        location ~ \.php$ {
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME \
          include fastcgi_params;
blog comments powered by Disqus