【问题标题】:Laravel 4.1 first route add, gives error.Laravel 4.1 第一条路线添加,给出错误。
【发布时间】:2014-05-23 05:25:25
【问题描述】:

我刚刚使用推荐的安装选项安装了 laravel 4.1。

composer create-project laravel/laravel your-project-name --prefer-dist

一切顺利,因为我能够看到/public/ 中的默认页面,然后我删除了.htaccess 文件,因为我使用的是 nginx,并在location ~ \.php$ { ... } 中为 nginx 添加了try_files $uri $uri/ /index.php?$query_string;,然后我创建了一个简单的路线

Route::get('/about', function()
{
    return "about page";
});

但我从 nginx 得到了常见的404 Not Found nginx/1.0.15。我什至对整个 laravel 文件夹都授予了 777 权限。可能是什么问题呢?

【问题讨论】:

  • 听起来更像是 nginx 问题而不是 laravel 问题。您是否能够显示默认主页?

标签: nginx laravel laravel-4


【解决方案1】:

您需要将您的 nginx 指向公共文件夹。这是我在 nginx 中的站点配置文件之一:

server {
    listen 80 default;
    server_name _;

    root /var/www/laravel/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

这样,你可以通过请求浏览到你的 laravel 项目:http://localhost/ 注意:也许你的 php cgi 不同:使用你已经拥有的 fastcgi_pass 规则。 并且读取.htaccess 文件不会造成任何伤害。

希望这对你有用。

【讨论】:

  • 谢谢。我创建了两个location /{ ... },我猜他们有冲突。
  • 欢迎查看我关于将 127.0.0.1:8080 更改为 localhost 的新问题 :)
猜你喜欢
  • 2023-03-26
  • 2021-04-13
  • 2014-09-18
  • 2016-05-23
  • 2019-12-09
  • 2017-01-04
  • 1970-01-01
  • 2014-01-10
  • 1970-01-01
相关资源
最近更新 更多