Tips / Nginx

Nginx configuration for CakePHP framework

CakePHP is a free open-source development framework for PHP. This fabulous framework can enable you to work in a structured and rapid way, without losing any flexibility while you write the code. Today we are going to share you a basic CakePHP configuration for Nginx webserver.

I will assume you have nginx and php-fpm properly installed and configured to work with sockets, otherwise, you should need to change fastcgi_pass_unix to, that is the default port and interface php-fpm listen to. Also, feel free to change domain.tld with your own domain name and root directory to the real directory of your app.

server {
    listen   80;
    rewrite ^(.*)$1 permanent;

server {
    listen   80;

    root   /var/www/;
    index  index.php;

    access_log /var/www/;
    error_log /var/www/;

    # main cakephp rewrite rule
    location / {
        try_files $uri $uri/ /index.php?$uri&$args;

        location ~ .php$ {
            root           /var/www/;
            try_files $uri =404;
            fastcgi_pass   unix:/tmp/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 4k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;


If you have troubles, please reffer to the official documentation.

Popular search terms:

  • cakephp nginx
  • nginx configuration cakephp
  • nginx directive for cakephp app
  • nginx configuration for cakephp app

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking