Kohana does not seem to work with NGiNX - nginx

Here is the error I get in the logs:
2012-08-22 17:20:35 --- ERROR: HTTP_Exception_404 [ 404 ]: Unable to find a route to match the URI: index.php ~ SYSPATH/classes/kohana/request.php [ 1126 ]
2012-08-22 17:20:35 --- STRACE: HTTP_Exception_404 [ 404 ]: Unable to find a route to match the URI: index.php ~ SYSPATH/classes/kohana/request.php [ 1126 ]
--
#0 /var/www/index.php(109): Kohana_Request->execute()
#1 {main}
Here is my nginx configs:
server {
listen 80;
server_name 000.000.00.00;
root /var/www;
index index.php;
location / {
try_files $uri $uri/ #kohana;
}
location ~ /\. {
deny all;
}
location ~* \.php$ {
try_files $uri $uri/ #kohana;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
location #kohana {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
In the front page I get:
HTTP_Exception_404 [ 404 ]: Unable to find a route to match the URI: index.php
and
DOCROOT/index.php [ 109 ] » Kohana_Request->execute()
Thanks in advance for any help!
UPDATE
Kohana::init(array(
'base_url' => '/',
));
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));

I had a similar issue and this was the nginx config we ended up with
server {
listen 80;
server_name <<INSERT SERVER NAME>>;
root /add/root/directory;
index index.php;
# ROUTING TO KOHANA IF REQUIRED
location / {
try_files $uri $uri/ #kohana;
}
# BLOCKS ACCESS TO . FILES (.svn, .htaccess, ...)
location ~ /\. {
deny all;
}
# FOR PHP FILES
location ~* \.php$ {
# PHP FILES MIGHT BE TO HANDLED BY KOHANA
try_files $uri $uri/ #kohana;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# HANDLES THE REWRITTEN URLS TO KOHANA CONTROLLER
location #kohana
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
# CACHE CONTROL FOR STATIC FILES
location ~* \.css|\.js|\.jpg|\.jpeg|\.png|\.gif|\.swf|\.svg|\.tiff|\.pdf$ {
expires 30d;
}
# REDIRECTING MEDIAS TO STATIC
location ^~ /medias/ {
rewrite ^/medias/(.*) http://static.xxxx.com/$1 permanent;
break;
}
}

Try browsing to http://localhost/ instead of http://localhost/index.php.
If that's not it, the example nginx config might help.

Related

How can Nginx use try_files only if file exists?

I have fully worked example of virtual host for a project on Symfony from ()[].
There is a code:
server {
listen 80;
server_name localhost www.localhost;
root /vagrant/web;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app_dev.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
#internal;
}
}
But I want to improve it a bit for me. How can I load maintenance.html by default instead of app_dev.php?
P.S. I need a behaviour like with try_files $uri /maintenance.html$is_args$args; instead of try_files $uri /app_dev.php$is_args$args;, but ONLY if maintenance.html exists
Solution from here with bit of comments
location / { #can be any location or even in server
if (-f $document_root/maintenance.html) {
return 503; #503 for search engines
}
... # the rest of your config goes here
}
error_page 503 #maintenance;
location #maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
I solved it with:
try_files $uri /maintenance.html$is_args$args /app_dev.php$is_args$args;

Nginx location for PHP files that do not exist

I have config(minimal):
server {
listen test.local:80;
server_name test.local;
server_name_in_redirect off;
location / {
root /data/www/test/public;
try_files $uri $uri/ /index.php?route=$uri&$args;
index index.html index.php;
}
location ~ \.php$ {
root /data/www/test/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/test/public$fastcgi_script_name;
fastcgi_param ...
...
}
}
Thats work file for urls /help/ or /contacts/ etc… (all redirect to index.php with get variables).
But if url, for example, /help.php or contacts.php, and this files not exists, I have output:
File not found.
How update my Nginx config? I need URLs, for example:
/help.php => /index.php?route=/help.php
/contacts.php?foo=bar... => /index.php?route=/contacts.php&args=…
Here is simple config for 404 error page . Its custom 404 page.
error_page 404 /404.php;
location /404.php {
root /var/www/public_html;
allow all;
}
Last part
Important line is ========== try_files $uri =404;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public_html$fastcgi_script_name;
include fastcgi_params;
}

nginx configuration for Laravel 4

I am trying to setup my Laravel 4 project using nginx . Here is my nginx server block for laravel :
server {
listen 80;
root /home/prism/www/laravel/public;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
But my problem is , Its showing "404 not found" error for all other routes except the default one , that comes with default installation .
This is an NGINX Configuration i've used with Laravel 4 and Laravel 4.1 that works.
server {
listen 80;
server_name sub.domain.com;
set $root_path '/var/www/html/application_name/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/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;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
you could try this for location / { ... }
location / {
try_files $uri $uri/ /index.php?$query_string;
}
$query_string worked for me.

Server configuration file for nginx

I'm trying to install Symfony on my php5-fpm+nginx server on ubuntu.
When i'm entering to /web/app_dev.php it's displaying an error :
An error occurred while loading the web debug toolbar (404: Not
Found).
Do you want to open the profiler?
When i'm entering to profiler(/web/app_dev.php/_profiler/0db7ac) it tells:
No input file specified.
I know there is a problem with my server configuration file. Here it is:
server {
listen 80;
# listen [::]:80 ipv6only=on;
root /home/marker/Projects/stereoshoots/www;
access_log /home/marker/Projects/stereoshoots/logs/access.log;
server_name stereoshoots.local;
index index.php index.html index.htm;
location / {
autoindex on;
# try_files $uri $uri/ #rewrite;
try_files $uri $uri/ /index.php;
}
# location #rewrite {
# rewrite ^/(.*)$ /index.php?q=$1;
# }
location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
access_log off;
expires 30d;
}
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
What should i edit, to get symfony installed right?
Thanks!
I think the only thing left is to pass the uri to the index.php
try_files $uri $uri/ /index.php$request_uri
Do you really have index.php?
Try this:
index app_dev.php;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app_dev.php/$1;
}
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_param SERVER_PORT 80;
fastcgi_param SERVER_NAME stereoshoots.local;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index app_dev.php;
}
Notice that I changed location ~ \.php$ to location ~ \.php

nginx Wordpress URL rewrite

I've just installed nginx 1.0.8 and php-fpm and for the last 30 minutes I'm trying to rewrite the URL for Wordpress.
Here is what the Wordpress URL should look like:
http://localhost/website/blog/2011/10/sample-post/
I've looked at this tutorial: http://wiki.nginx.org/WordPress + many other on the web but every time I receive an 404 error (sometimes 403).
Here is what I did in my configuration file:
location /website/blog {
try_files $uri $uri/ /website/blog/index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(/website/blog)(/.*)$;
include fastcgi_params;
error_page 404 /404.html;
}
With this configuration I'm receiving "403 forbidden" status.
What am I missing?
Could be the permission of the root site folder
This is an example that i use to wordpress
server {
listen 80;
server_name www.mysite.com mysite.com;
root /srv/www/mysite.com/public_html;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
include /srv/www/mysite.com/public_html/*.conf;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Did you try restarting nginx after you have saved your config?
Also, check out my nginx/WordPress setup guide here:
http://themesforge.com/featured/high-performance-wordpress-part-3/

Resources