kohana 3.1 in subdirectory + ubuntu 14.04 + php-fpm + nginx 404 errors

gabereal asked:

i have an old kohana app that i’m trying to put on my VPS but can’t seem to get it working. i’ve spent hours googling and looking at cached forum answers. i have tried them all and nothing seems to work. admittedly, i have no idea how to deal with nginx. my local version of the app works fine with apache. i’m one step away from just canceling my linode account and getting shared hosting! please talk me off this ledge.

my vps:
ubuntu 14.04LTS with php5-fpm and nginx 1.4.6.

i am serving everything from my user directory.

my nginx sites-available file:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /home/gabreal/Sites/public;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / {

    try_files $uri $uri/ @kohana =404;

error_page 404 /404.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;

# pass the PHP scripts to FastCGI server listening on
location ~ .php$ {
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

location @kohana {
    rewrite ^/(.+)$ /index.php$request_uri last;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /.ht {
    deny all;

my kohana application is in the directory like so:

│ ├── horizons/
│ │ ├── grader/ (aka the kohana application)
│ │ │ ├── index.php
│ │ │ ├── application/
│ │ │ ├── system/

when i visit the application by going to http://example.com/horizons/grader the kohana bootstrap file loads and all the redirects are called. for example, my default route redirects you to a start page. if you aren’t logged in, you go to ‘user/login’. the url is being set correctly. going to the url above, the browser redirects to http://example.com/horizons/grader/user/login but i get nginx 404 page.

so somehow the controller/action pattern is just not working with this nginx setup.

please help for the love of whatever you love in this world.


just fyi, i installed phpmyadmin and it is working perfectly. i still can’t get kohana to work though…


i did a fresh install of kohana and tried to set up a few basic controllers. only the default controller works just like in my application. so, going to the base url for my application ALWAYS works but going directly to any /controller/action/id type of resource gives me nginx 404 error on both a fresh install and my existing application.

My answer:

This is the obvious problem:

    try_files $uri $uri/ @kohana =404;

The =404, and the entire @kohana location block, are probably combining to cause the problem.

You can simplify this by getting rid of the @kohana location block, and simplifying try_files to:

    try_files $uri $uri/ /index.php;

(Kohana doesn’t need any other parameters when you pass the request to index.php; see the Clean URLs page for details.)

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.