NGINX (Engine-X) Rewrite Rules For CakePHP
April 17th, 2008
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;
server_name somedomain.com;
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/somedomain.com/current;
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 ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \
/var/www/sites/somedomain.com/current$fastcgi_script_name;
include fastcgi_params;
}
}
1 Response to “NGINX (Engine-X) Rewrite Rules For CakePHP”
Sorry, comments are closed for this article.
July 15th, 2008 at 03:40 AM
Hey Tim, I managed to get your code working when Cake was in the root, but when I moved cake to a subdirectory (wwww.mydomain.com/myapp) it broke. I tried playing around with different things but can’t seem to get it to work. Any help would be much appreciated :)