未找到Laravel 4路由404

时间:2014-05-08 04:09:04

标签: php .htaccess mod-rewrite nginx laravel-4

我几个小时前刚刚和Laravel一起玩过,似乎撞墙了。我在这里看到过类似的问题,但他们是关于Apache的

Route::get('/', function()
{
return 'hello world';
});

上面的路由适用于localhost/helloworld/public/,但是当我更改为

Route::get('about', function()
{
return 'this is about';
});

我使用了这个网址localhost/helloworld/public/about,它一直显示404 Not Found。即使我尝试localhost/helloworld/public/index.php/about,它仍然无效。

这是我的nginx default.conf 这是我的.htaccess

我听说过在nginx上启用mod_rewrite但是还不知道如何做到这一点。

请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:1)

摘自here

这是我使用的Laravel 4和Laravel 4.1的NGINX配置。

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;
    }

}