Configuración nginx para cakephp

Nginx es un servidor web que está ganando mucha popularidad. Igual que Lighttpd, usa eficientemente los recursos del sistema. En el caso de nginx, no hay ficheros .htaccess, así que es necesario crear esas reglas de redirección directamente en la configuración del servidor. Dependiendo de tu configuración igual tendrás que ajustar un poco este fichero. Como mínimo necesitarás PHP funcionando como instancia FastCGI. Puedes ver los detalles en la documentación de instalación de nginx.

#
# nginx configuration example for CakePHP 2.x
#
server {
    listen       80;
    server_name  cakephp2.example;
    root         /var/www/cakephp2/app/webroot;

    access_log  /var/log/nginx/cakephp2.access.log;
    error_log  /var/log/nginx/cakephp2.error.log;

    location / {
        index  index.php;
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
    }

    location ~ \.php/ {
        include        fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        log_not_found off;
        access_log off;
    }

    #error_page  404              /404.html;
    #location = /404.html {
    #    root   /usr/share/nginx/html;
    #}

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /(\.ht|\.user.ini|\.git|\.hg|\.bzr|\.svn) {
        deny  all;
    }
}

Volver al índice del blog