NGINX with Kohana 3.x friendly URLs

I really enjoy working with Kohana and since I got a server from one of the hosting companies listed at LowEndBox, I decided to ditch Apache and go with Nginx, thing is… I also like pretty URLs 🙂

As a backup from the comment located here: http://forum.kohanaframework.org/discussion/comment/11553/#Comment_11553

I’m copying and pasting it in my blog for easier reference, plus it’s modified to fit my servers configuration:

location / {
    index    index.php index.html;

    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php/$1 last;
    }

    include  /home/httpd/domains/example.com/htaccess;
}

location ~ .php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /home/httpd/domains/example.com/html$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:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /home/httpd/domains/example.com/html/index.php;

    fastcgi_param  PATH_INFO $path_info;
    include /etc/nginx/fastcgi_params;
}
Tagged , , . Bookmark the permalink.

One Response to NGINX with Kohana 3.x friendly URLs

  1. klay says:

    Чушь
    <code>
     
    server {
      listen 127.0.0.1:80;
      server_name site_name.local http://www.site_name.local;
     
      # PublicRoot нашего сайта
      root /srv/http/site_name/public_html;
      index index.php;
     
      # Устанавливаем пути к логам
      # Для access_log делаем буферизацию
      access_log  /srv/http/site_name/logs/access.log main buffer=50k;
      error_log   /srv/http/site_name/logs/error.log;
     
      # Отключаем логирование для robots.txt
      location = /robots.txt  {
        access_log off;
        log_subrequest off;
        log_not_found off;
      }
     
      # Отключаем логирование для favicon.ico
      location = /favicon.ico {
        access_log off;
        log_subrequest off;
        log_not_found off;
      }
     
      # Отключаем логирование для sitemap.xml
      location = /sitemap.xml {
        access_log off;
        log_subrequest off;
        log_not_found off;
      }
     
      # Отключаем логирование для *.css И *.js файлов
      #location ~* ^.+\.(css|js)$ {
      #  access_log off;
      #  log_subrequest off;
      #  log_not_found off;
      #}
     
      # Также отключаем логи для картинок, файлов
      #location ~* ^.+\.(bmp|gif|jpg|jpeg|ico|png|swf)$ {
      #  access_log off;
      #  log_subrequest off;
      #  log_not_found off;
      #}
     
      # Блокируем доступ для всех скрытых файлов, (.htaccess, .git, .svn и т.д.)
      location ~ /\. {
        deny  all;
      }
     
      location / {
        if (!-f $request_filename) {
          rewrite ^/(.*)$ /index.php;
        }
      }
      # Подключаем обработчик php-fpm
      location ~ \.php$ {
        # Этой строкой мы указываем,
        # что текущий location можно использовать
        # только для внутренних запросов
        # Тем самым запрещаем обработку всех php файлов,
        # для которых не создан location
        internal;
     
        # php-fpm. Подключение через сокет.
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  DOCUMENT_ROOT  /srv/http/site_name/public_html;
        fastcgi_param  SCRIPT_FILENAME  /srv/http/site_name/public_html$fastcgi_script_name;
        include fastcgi_params;
      }
    }
    </code>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • IGlr