TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
Nginx Rewrite Rule
  • Sample Nginx configuration for handling Kohana.

    server
    {
    listen 80;
    server_name localhost;
    root /var/www/localhost;
    index index.php;

    location /
    {
    try_files $uri $uri/ @kohana;
    }

    # Handles non kohana requests.
    location ~* \\\.php$
    {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    include fastcgi_params;
    }

    location @kohana
    {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    include fastcgi_params;
    }
    }
  • Thanks for sharing.
  • for kohana_3.0 api_changes

    location / {
        index    index.php index.html;
    
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    
        include  /var/www/domain.com/htaccess;
    }
    
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:8888;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/domain.com/public$fastcgi_script_name;
    
        include /etc/nginx/fastcgi_params;
    }
    
    # kohana
    set  $path_info "";
    location /index.php {
        if ($uri ~ "^/index.php(/.+)$") {
            set  $path_info  $1;
        }
        fastcgi_pass   127.0.0.1:8888;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/domain.com/public/index.php;
    
        fastcgi_param  PATH_INFO $path_info;
        include /etc/nginx/fastcgi_params;
    }
    
  • Running 2.3.1 on Ubuntu Hardy with Nginx 5.33.x , I had to change the rewrite part to:

    location / {
    if (-f $request_filename) {
    expires max;
    break;
    }
    if (!-e $request_filename) {
    rewrite ^/(.+)$ /index.php?kohana_uri=$1 last; # NOTICE THIS LINE CHANGE
    break;
    }
    }
  • Took me a massive long time to configure Nginx for Kohana. None of the examples above worked for me. So I wrote the VirtualHost from scratch: http://vidax.net/blog/en/2010/06/kohana-with-nginx-virtualhost-configuration/
    Hope it helps


    Axel
  • did you try this one posted by shadowhand a while back: http://gist.github.com/383516
  • It is also on the guide near the end.

  • Posted By: axel

    Took me a massive long time to configure Nginx for Kohana. None of the examples above worked for me. So I wrote the VirtualHost from scratch:http://vidax.net/blog/en/2010/06/kohana-with-nginx-virtualhost-configuration/
    Hope it helps

    Axel



    Axel, thanks for writing that up. You just cured my headache!