I'm attempting to set up the Laravel PHP Framework to work with Nginx. Here is my directory structure:

/project
   /application
   /laravel
   /public
      index.php
   /legacy
      /index.php
      /stylesheets
         default.css

Basically what I have is a standard Laravel download w/ a legacy folder thrown in which holds all of the files from my non-MVC project.

我需要Nginx首先判断请求的页面/文件是否存在于legacy中,如果存在,那么我想使用它.否则,我想回到拉维尔的index.php文件,它位于project/public/.

我不是Nginx配置方面的专家,所以如果您能提供任何帮助,我们将不胜感激.

推荐答案

server {
    server_name .laravel.dev;
    root /home/tamer/code/laravel/public;

    index index.php index.html;

    #browse folders if no index file
        autoindex on; 

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }


    # canonicalize codeigniter url end points
    # if your default controller is something other than "welcome" you should change the following
    if ($request_uri ~* ^(/lobby(/index)?|/index(.php)?)/?$)
    {
        rewrite ^(.*)$ / permanent;
    }

    # removes trailing "index" from all controllers
    if ($request_uri ~* index/?$)
    {
        rewrite ^/(.*)/index/?$ /$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # catch all
    error_page 404 /index.php;

        location ~ \.php$ {
        try_files $uri =404;
                fastcgi_pass  unix:/tmp/php.socket;
                fastcgi_index index.php;
                #include fastcgi_params;
                include /home/tamer/code/nginx/fastcgi_params;
        }
        access_log /home/tamer/code/laravel/storage/logs.access.log;
        error_log  /home/tamer/code/laravel/storage/logs.error.log;
}

Laravel相关问答推荐

Laravel中的策略对我不起作用,这是我的代码

如何使用 laravel 更新单个值

验证错误后的 Laravel 自定义重定向

Carbon现在时间错了

函数 mcrypt_get_iv_size() 在 Laravel 4 上已弃用

Laravel excel maatwebsite 3.1 导入,excel 单元格中的日期列返回为未知格式数字.如何解决这个问题?

如何在 Laravel 中为模型命名,以免与现有类发生冲突?

如何在 laravel blade中进行一次性推送

如何卸载 Laravel?

如何从 laravel 中的现有数据库创建迁移

干预图像:直接从带有原始文件名和分机的网址保存图像?

Laravel 5.3 通知 - 仅使用Electron邮件地址通知

如何在 Laravel 视图中找到当前语言?

Laravel 接口

Laravel php artisan 服务于模仿 HTTPS

控制器中的laravel foreach循环

在 laravel Passport 客户端应用程序中使用访问令牌获取用户数据

开发中的 Laravel 和视图缓存 - 无法立即看到更改

Laravel 5 Illuminate\Http\Request 的方法不允许静态调用

以编程方式而不是从 CLI 运行 Laravel 5 seeder